estimateCompressedSize

fnsize_t estimateCompressedSize(CompressionFormat fmt, size_t inputSize) pure nothrow @nogc

Estimate the maximum compressed output size for a given input size and format.

This function returns an upper bound suitable for pre-allocating output buffers. The actual compressed size may be smaller (for compressible data) or close to this bound (for incompressible/random data).

Parameters

fmtThe compression format to estimate for.
inputSizeSize of the uncompressed input data in bytes.

Returns

Upper bound estimate of compressed size in bytes.

Examples

// Pre-allocate buffer for GZIP compression
auto inputData = cast(ubyte[])"Hello, World!";
auto bufferSize = estimateCompressedSize(CompressionFormat.GZIP, inputData.length);
auto outputBuffer = new ubyte[](bufferSize);