Which format to use for the deflated stream. In case ZlibFormat.gz, the gzHeader field will be written if set.
If set, will be assigned to the Gz header once it is known
Advanced parameters See zlib's documentation of deflateInit2. windowBits can be 0 if format is ZlibFormat.zlib. Otherwise it must be between 9 and 15 included.
import test.util; import std.array : join; auto def = Deflate.init; auto inf = Inflate.init; const len = 100_000; const phrase = cast(const(ubyte)[]) "Some very repetitive phrase.\n"; const input = generateRepetitiveData(len, phrase).join(); // deflating const squized = only(input).squiz(def).join(); // re-inflating const output = only(squized).squiz(inf).join(); assert(squized.length < input.length); assert(output == input); // for such long and repetitive data, ratio is around 0.3% const ratio = cast(double) squized.length / cast(double) input.length; assert(ratio < 0.004);
import test.util; import std.array : join; const len = 100_000; const phrase = cast(const(ubyte)[]) "Some very repetitive phrase.\n"; const input = generateRepetitiveData(len, phrase).join(); GzHeader inHead; inHead.mtime = Clock.currTime; inHead.os = GzHeader.Os.fatFs; inHead.text = Yes.text; inHead.filename = "boring.txt"; inHead.comment = "A very boring file"; // deflating const squized = only(input) .deflateGz(inHead) .join(); // re-inflating GzHeader outHead; int numCalls; void setOutHead(GzHeader gzh) { outHead = gzh; numCalls++; } const output = only(squized) .inflateGz(&setOutHead) .join(); assert(squized.length < input.length); assert(output == input); assert(inHead == outHead); assert(numCalls == 1);
import test.util; import std.array : join; const len = 100_000; const phrase = cast(const(ubyte)[]) "Some very repetitive phrase.\n"; const input = generateRepetitiveData(len, phrase).join(); // deflating const squized = only(input) .deflateRaw() .join(); // re-inflating const output = only(squized) .inflateRaw() .join(); assert(squized.length < input.length); assert(output == input);
Zlib's inflate algorithm