Exception thrown on errors in compression functions, likely caused by corrupted data.
Component that returns a Range that will compress src using LZ77 compression.
Component to expand compressed result of LZ77 Compress.
Compute the max size of a buffer needed to hold the compressed result.
This program takes a filename as an argument, compresses it, expands it, and verifies that the result matches the original contents.
int main(string args[]) { import std.stdio; import std.algorithm; import std.file; import std.compression.lz77; string filename; if (args.length < 2) { printf("need filename argument\n"); return 1; } else filename = args[1]; ubyte[] si = cast(ubyte[])std.file.read(filename); // Compress auto di = new ubyte[maxCompressedSize(si.length)]; auto result = si.compress().copy(di); di = di[0..$ - result.length]; writefln("Compression done, srclen = %s compressed = %s", si.length, di.length); // Decompress ubyte[] si2 = new ubyte[si.length]; result = di.expand().copy(si2); assert(result.length == 0); writefln("Decompression done, dilen = %s decompressed = %s", di.length, si2.length); if (si != si2) { writeln("Buffers don't match"); assert(0); } return 0; }
References: Wikipedia
See Source File
$(SARGONSRC src/sargon/_lz77.d)
Copyright Digital Mars 2013.
Components that can compress and expand ranges.
Description: Compression is useful for storage and transmission data formats. This compresses using a variant of the LZ77 compression algorithm. compress() and expand() are meant to be a matched set. Users should not depend on the particular data format.