Inflate

Zlib's inflate algorithm

Members

Classes

Stream
class Stream
Undocumented in source.

Functions

end
void end(Stream stream)
Undocumented in source. Be warned that the author may not have intended to support it.
initialize
Stream initialize()
Undocumented in source. Be warned that the author may not have intended to support it.
process
Flag!"streamEnded" process(Stream stream, Flag!"lastChunk" )
Undocumented in source. Be warned that the author may not have intended to support it.
reset
void reset(Stream stream)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

format
ZlibFormat format;

Which format to use for the deflated stream. In case ZlibFormat.gz, the gzHeader field will be written if set.

gzHeaderDg
GzHeaderDg gzHeaderDg;

If set, will be assigned to the Gz header once it is known

windowBits
int windowBits;

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.

Examples

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);

Meta