squiz_box.squiz

Compression and decompression streaming algorithms.

Each compression or decompression algorithm is represented by a struct that contains parameters for compression/decompression. Besides the parameters they carry, algorithms have no state. Each algorithm instance can be used for an unlimited number of parallel jobs.

The algorithms create a stream, which carry the state and allocated resources of the ongoing compression.

The compression/decompression jobs are run by the squiz function, or one of the related helpers built upon it (e.g. deflate, deflateGz, inflate, ...).

squiz and related functions take and InputRange of ubyte[] and return an InputRange of ubyte[]. This allows streaming in the most natural way for a D program and provide the greatest versatility. It is possible to read the data from any source (file, network, memory), process the data, and write to any kind of destination. This also allows to process gigabytes of data with little memory usage.

Compression often wraps the compressed data with header and trailer that give the decompression algorithm useful information, especially to check the integrity of the data after decompression. This is called the format. Some compressions algorithms offer different formats, and sometimes the possibility to not wrap the data at all (raw format), in which case integrity check is not performed. This is usually used when an external integrity check is done, for example when archiving compressed stream in Zip or 7z archives.

Members

Aliases

ByteChunk
alias ByteChunk = const(ubyte)[]

definition of a byte chunk, which is the unit of data exchanged during I/O and data transformation operations

ByteRange
alias ByteRange = InputRange!ByteChunk

A dynamic type of input range of chunks of bytes

GzHeaderDg
alias GzHeaderDg = void delegate(GzHeader header)

Type of delegate to use as callback for Inflate.gzHeaderDg

Classes

Bz2Stream
class Bz2Stream
Undocumented in source.
CopyStream
class CopyStream

Copy algorithm do not transform data at all This is useful in cases of reading/writing data that may or may not be compressed. Using Copy allows that the same code handles both kind of streams.

DataException
class DataException

Exception thrown when inconsistent data is given to a decompression algorithm. I.e. the data was not compressed with the corresponding algorithm or the wrapping format is not the one expected.

LzmaStream
class LzmaStream
Undocumented in source.
ZlibStream
class ZlibStream
Undocumented in source.
ZstdStream
class ZstdStream
Undocumented in source.

Enums

LzmaCheck
enum LzmaCheck

Integrity check to include in the compressed data (only for the Xz format) Default for xz is CRC-64.

LzmaFilter
enum LzmaFilter

Filters to use with the LZMA compression.

LzmaFormat
enum LzmaFormat

Header/trailer format for Lzma compression

ZlibFormat
enum ZlibFormat

Describe what type of header and trailer are wrapping a deflated stream.

Functions

compressBzip2
auto compressBzip2(I input, size_t chunkSize)

Returns an InputRange containing the input data processed through Bzip2 compression.

compressLzmaRaw
auto compressLzmaRaw(I input, size_t chunkSize)
Undocumented in source. Be warned that the author may not have intended to support it.
compressXz
auto compressXz(I input, size_t chunkSize)
Undocumented in source. Be warned that the author may not have intended to support it.
compressZstd
auto compressZstd(I input, size_t chunkSize)
Undocumented in source. Be warned that the author may not have intended to support it.
copy
auto copy(I input, size_t chunkSize)

Copy algorithm do not transform data at all This is useful in cases of reading/writing data that may or may not be compressed. Using Copy allows that the same code handles both kind of streams.

decompressBzip2
auto decompressBzip2(I input, size_t chunkSize)

Returns an InputRange streaming over data decompressed with Bzip2.

decompressLzmaRaw
auto decompressLzmaRaw(I input, size_t chunkSize)
Undocumented in source. Be warned that the author may not have intended to support it.
decompressXz
auto decompressXz(I input, size_t chunkSize)
Undocumented in source. Be warned that the author may not have intended to support it.
decompressZstd
auto decompressZstd(I input, size_t chunkSize)
Undocumented in source. Be warned that the author may not have intended to support it.
deflate
auto deflate(I input, size_t chunkSize)

Returns an InputRange containing the input data processed through Zlib's deflate algorithm. The produced stream of data is wrapped by Zlib header and trailer.

deflateGz
auto deflateGz(I input, GzHeader header, size_t chunkSize)
auto deflateGz(I input, size_t chunkSize)

Returns an InputRange containing the input data processed through Zlib's deflate algorithm. The produced stream of data is wrapped by Gzip header and trailer. Suppliying a header is entirely optional. Zlib produces a default header if not supplied. The default header has text false, mtime zero, unknown os, and no name or comment.

deflateRaw
auto deflateRaw(I input, size_t chunkSize)

Returns an InputRange containing the input data processed through Zlib's deflate algorithm. The produced stream of data isn't wrapped by any header or trailer.

inflate
auto inflate(I input, size_t chunkSize)

Returns an InputRange streaming over data inflated with Zlib. The input data must be deflated with a zlib format.

inflateGz
auto inflateGz(I input, GzHeaderDg headerDg, size_t chunkSize)
auto inflateGz(I input, size_t chunkSize)

Returns an InputRange streaming over data inflated with Zlib. The input data must be deflated with a gz format. If headerDg is not null, it will be called as soon as the header is read from the stream.

inflateRaw
auto inflateRaw(I input, size_t chunkSize)

Returns an InputRange streaming over data inflated with Zlib. The input must be raw deflated data

isLegacy
bool isLegacy(LzmaFormat format)

Whether this is a legacy format

isRaw
bool isRaw(LzmaFormat format)

Whether this is a raw format

isText
Flag!"text" isText(const(ubyte)[] data)

Helper to set GzHeader.text Will check if the data are all ascii characters

squiz
auto squiz(I input, A algo, size_t chunkSize)
auto squiz(I input, A algo, ubyte[] chunkBuffer)

Returns an InputRange containing the input data processed through the supplied algorithm.

squizAlgo
SquizAlgo squizAlgo(A algo)

Get a runtime type for the provided algorithm

squizMaxOut
auto squizMaxOut(I input, A algo, ulong maxOut, size_t chunkSize)

Same as squiz, but will stop encoding/decoding after len bytes has been written out Useful to decode some raw encoded streams where the uncompressed size is known and the algorithm not always report Yes.streamEnded.

squizReuse
auto squizReuse(I input, A algo, S stream, ubyte[] chunkBuffer)

Returns an InputRange containing the input data processed through the supplied algorithm. To the difference of squiz, squizReuse will not manage the state (aka stream) of the algorithm, which allows to reuse it (and its allocated resources) for several jobs. squizReuse will drive the algorithm and move the stream forward until processing is over. The stream must be either freshly initialized or freshly reset before being passed to this function.

zFlushToString
string zFlushToString(int flush)
Undocumented in source. Be warned that the author may not have intended to support it.
zResultToString
string zResultToString(int res)
Undocumented in source. Be warned that the author may not have intended to support it.

Interfaces

SquizAlgo
interface SquizAlgo

A squiz algorithm whom type is erased behind an interface. This helps to choose algorithm at run time.

SquizStream
interface SquizStream

A state carrying, processing stream for squiz algorithms. The stream does not carry any buffer, only slices to external buffer. One may normally not use this directly as everything is handled by the squiz function.

Manifest constants

defaultChunkSize
enum defaultChunkSize;

default chunk size for data exchanges and I/O operations

Mixin templates

ZlibLikeTotalInOutImpl
mixintemplate ZlibLikeTotalInOutImpl()
Undocumented in source.

Structs

CompressBzip2
struct CompressBzip2

Compression with the Bzip2 algorithm.

CompressLzma
struct CompressLzma
Undocumented in source.
CompressZstd
struct CompressZstd

Zstandard is a fast compression algorithm designed for streaming. See zstd.h (enum ZSTD_cParameter) for details.

Copy
struct Copy

Copy algorithm do not transform data at all This is useful in cases of reading/writing data that may or may not be compressed. Using Copy allows that the same code handles both kind of streams.

DecompressBzip2
struct DecompressBzip2

Decompression of data encoded with Bzip2.

DecompressLzma
struct DecompressLzma
Undocumented in source.
DecompressZstd
struct DecompressZstd
Undocumented in source.
Deflate
struct Deflate

Zlib's deflate algorithm

GzHeader
struct GzHeader

Header data for the Gzip format. Gzip includes metadata about the file which is compressed. These can be specified here when compressing from a stream rather than directly from a file.

Inflate
struct Inflate

Zlib's inflate algorithm

Templates

StreamType
template StreamType(A)

Get the type of a SquizStream for the Squiz algorithm

isByteRange
template isByteRange(BR)

Static check that a type is a byte range.

isSquizAlgo
template isSquizAlgo(A)

Check whether a type is a proper squiz algorithm.

Meta