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
a local clone.
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: map; UnCompress decmp = new UnCompress; foreach (chunk; stdin.byChunk(4096).map!(x => decmp.uncompress(x))) { chunk.to!string.write; }
References: Wikipedia
License:
Authors:
Source: std/zlib.d
Compute the Adler-32 checksum of a buffer's worth of data.
Parameters:uint adler the starting checksum for the computation. Use 1 for a new checksum. Use the output of this function for a cumulative checksum. const(void)[] buf buffer containing input data Returns:A uint checksum for the provided input data and starting checksumSee Also:Examples:static ubyte[] data = [1,2,3,4,5,6,7,8,9,10]; uint adler = adler32(0u, data); assert(adler == 0xdc0037);
Compute the CRC32 checksum of a buffer's worth of data.
Parameters:uint crc the starting checksum for the computation. Use 0 for a new checksum. Use the output of this function for a cumulative checksum. const(void)[] buf buffer containing input data Returns:A uint checksum for the provided input data and starting checksumCompress data
Parameters:Returns:the compressed data- Decompresses the data in srcbuf[].Parameters:
const(void)[] srcbuf buffer containing the compressed data. size_t destlen size of the uncompressed data. It need not be accurate, but the decompression will be faster if the exact size is supplied. int winbits the base two logarithm of the maximum window size. Returns:the decompressed data. - the header format the compressed stream is wrapped in
- a standard zlib header
- used when decompressing. Try to automatically detect the stream format by looking at the data
- Used when the data to be compressed is not all in one buffer.
- Constructor.Parameters:
int level compression level. Legal values are 1..9, with 1 being the least compression and 9 being the most. The default value is 6. HeaderFormat header sets the compression type to one of the options available in HeaderFormat. Defaults to HeaderFormat.deflate. See Also: - Compress the data in buf and return the compressed data.Returns:the compressed data. The buffers returned from successive calls to this should be concatenated together.
- Compress and return any remaining data. The returned data should be appended to that returned by compress().Parameters:
int mode one of the following: - Z_SYNC_FLUSH
- Syncs up flushing to the next byte boundary. Used when more data is to be compressed later on.
- Z_FULL_FLUSH
- Syncs up flushing to the next byte boundary. Used when more data is to be compressed later on, and the decompressor needs to be restartable at this point.
- Z_FINISH
- (default) Used when finished compressing the data.
- Used when the data to be decompressed is not all in one buffer.
- Construct. destbufsize is the same as for D.zlib.uncompress().
- Decompress the data in buf and return the decompressed data. The buffers returned from successive calls to this should be concatenated together.
- Decompress and return any remaining data. The returned data should be appended to that returned by uncompress(). The UnCompress object cannot be used further.
Copyright Digital Mars 2000 - 2011.
| Page generated by
Ddoc on (no date time)