ddn.compressor.bzip2
ddn.compressor.bzip2
High-performance BZIP2 compression provider for ddn.api.compressor. This is a pure D implementation of the BZIP2 algorithm designed to match the performance of the system bzip2 tool.
The BZIP2 algorithm consists of the following stages:
- Run-Length Encoding (RLE1): Initial pass limiting runs to 255.
- Burrows-Wheeler Transform (BWT): Reversible block sort.
- Move-To-Front (MTF): Exploits locality in BWT output.
- Zero Run-Length Encoding (RLE2): Encodes zeros as RUNA/RUNB.
- Huffman Coding: Multiple tables with selectors.
Features:
- Supports both streaming and block compression.
- Compression levels map to bzip2's blockSize100k (1-9).
- Fully DDoc-documented.
Copyright
BSD-3-Clause
Module Initializers 1
shared static this
()Types 11
structBwtResult
BWT transform result.
Fields
ubyte[] outputuint origPtrstructMtfResult
MTF transform result.
Fields
ubyte[] outputbool[256] inUseint nInUsestructRle2Result
RLE2 encode result.
Fields
ushort[] symbolsint nInUsestructHuffEncEntry
Huffman encoding table entry.
Fields
uint codeubyte lenstructHuffDecTable
Build Huffman encoding table.
Parameters
lengths | Code lengths for each symbol. |
Returns
Encoding table.
Huffman decoding table.
Fields
uint[] limituint[] baseuint[] permint minLenint maxLenstructBitWriter
Bit writer for MSB-first bit packing.
Fields
ubyte[] buffersize_t posuint bsBuffint bsLiveMethods
const(ubyte)[] consumeOutput() @safeFlush complete bytes and return them, keeping partial bits in buffer.structBitReader
Fields
const(ubyte)[] datasize_t bytePosuint bsBuffint bsLiveMethods
structCompressedBlock
Compressed block result.
Fields
ubyte[] datauint blockCrcstructDecompressedBlock
Decompressed block result.
Fields
ubyte[] datauint blockCrcbool isEosclassBzip2Compressor : Compressor
BZIP2 streaming compressor.
Methods
void setOutputSink(OutputSink sink)void setProgressCallback(ProgressCallback callback)void write(const(ubyte)[] data)void finish()void reset()Constructors
this(CompressionOptions opts)Create a new BZIP2 compressor.classBzip2Decompressor : Decompressor
BZIP2 streaming decompressor.
Methods
void setOutputSink(OutputSink sink)void setProgressCallback(ProgressCallback callback)void write(const(ubyte)[] data)void finish()void reset()Constructors
this(DecompressionOptions opts)Create a new BZIP2 decompressor.Functions 18
fn
uint bz2Crc32Update(uint crc, ubyte b) pure nothrow @nogc @safeCompute BZIP2 CRC32 for a single byte.fn
size_t rle1EncodeCalcSize(const(ubyte)[] input) pure nothrow @nogc @safeCalculate the size of RLE1 encoded output.fn
size_t rle1Encode(const(ubyte)[] input, ubyte[] output) pure nothrow @nogc @safeEncode data using RLE1.fn
BwtResult bwtTransform(const(ubyte)[] input) purePerform the Burrows-Wheeler Transform on the input data.fn
ubyte[] mtfInverseTransform(const(ubyte)[] indices, const bool[256] inUse, int nInUse) pure @safeInverse MTF transform.fn
Rle2Result rle2Encode(const(ubyte)[] mtfIndices, int nInUse) pure @safeEncode MTF output using RLE2 (zero run encoding).fn
ubyte[] rle2Decode(const(ushort)[] symbols, int nInUse,
size_t maxOutput = size_t.max) @trustedDecode RLE2 to MTF indices.fn
ubyte[] generateHuffmanLengths(const(uint)[] frequencies, int alphaSize, int maxLen = BZ_MAX_CODE_LEN) pureGenerate Huffman code lengths from frequencies.fn
HuffDecTable buildHuffmanDecodeTable(const(ubyte)[] lengths) pure @safeBuild Huffman decoding table.fn
int determineNumGroups(int nMTF) pure nothrow @nogcDetermine number of Huffman tables based on data size.fn
CompressedBlock compressBlock(const(ubyte)[] input, int blockSize100k, uint originalDataCrc = uint.max)Compress a block of RLE1-encoded data into a BZIP2 block.fn
DecompressedBlock decompressBlock(ref BitReader reader, int blockSize100k = 9)Decompress a single block.