std.zlib

  • Compress/decompress data using the zlib library.

    Examples

  • If you have a small buffer you can use compress and
  • uncompress directly.
  • -------
  • import std.zlib;
  • auto src =
  • "the quick brown fox jumps over the lazy dog\r
  • the quick brown fox jumps over the lazy dog\r";
  • ubyte[] dst;
  • ubyte[] result;
  • dst = compress(src);
  • result = cast(ubyte[]) uncompress(dst);
  • assert(result == src);
  • -------
  • When the data to be compressed doesn't fit in one buffer, use
  • Compress and UnCompress.
  • -------
  • import std.zlib;
  • import std.stdio;
  • import std.conv : to;
  • import std.algorithm.iteration : map;
  • UnCompress decmp = new UnCompress;
  • foreach (chunk; stdin.byChunk(4096).map!(x => decmp.uncompress(x)))
  • {
  • chunk.to!string.write;
  • }
  • -------
  • References:
  • Wikipedia
  • Source: std/zlib.d