Note: This website is archived. For up-to-date information about D projects and development, please visit


Part of StandardLibraryCategory


A simplified version of the zip example that Walter B. posted. It only has zlib's compress and uncompress calls to minimize "distractions" from using zlib.


import std.zlib; 

int main(char[][] args)
    ubyte[] beforeCompression = cast(ubyte[])
"the quick brown fox jumps over the lazy dog\r
the quick brown fox jumps over the lazy dog\r
    ubyte[] compressed;
    ubyte[] afterDecompression;

    compressed = cast(ubyte[])std.zlib.compress(cast(void[])beforeCompression);
    afterDecompression = cast(ubyte[])std.zlib.uncompress(cast(void[])compressed);

    assert(beforeCompression == afterDecompression);
    printf("Success! Uncompressed Size: %d Compressed Size: %d\n",
      beforeCompression.length, compressed.length);

    return 0;


Contributed by Lynn.