View source code
Display the source code in std/zlib.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Module 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

Functions

NameDescription
adler32(adler, buf)

Compute the Adler-32 checksum of a buffer's worth of data.

compress(srcbuf, level)

Compress data

crc32(crc, buf)

Compute the CRC32 checksum of a buffer's worth of data.

uncompress(srcbuf, destlen, winbits) Decompresses the data in srcbuf[].

Classes

NameDescription
Compress Used when the data to be compressed is not all in one buffer.
UnCompress Used when the data to be decompressed is not all in one buffer.
ZlibException Errors throw a ZlibException.

Enums

NameDescription
HeaderFormat the header format the compressed stream is wrapped in

Authors

Walter Bright

License

Boost License 1.0.