lz4CompressBlock

private fnubyte[] lz4CompressBlock(const(ubyte)[] src, int level = 1)

Compress a single block of data using the LZ4 block format.

This function performs real LZ4 compression using match-finding algorithms. It finds repeated sequences in the input and encodes them as back-references (matches) to achieve compression.

The compression level controls both the hash table size and the matching strategy:

  • Level 0: Store-only mode. Returns null to signal the caller

should emit an uncompressed block.

  • Levels 1-3: Fast compression with smaller hash tables (4KB-16KB)

and greedy matching.

  • Levels 4-6: Default compression with 64KB hash table and greedy

matching.

  • Levels 7-9: High compression (HC mode) with 64KB hash table and

lazy matching for better compression ratios.

The output conforms to the LZ4 block format specification and can be decoded by any standard LZ4 decoder.

Parameters

srcInput bytes to compress.
levelCompression level (0-9). Default is 1 for fast compression.

Returns

Newly allocated array containing the LZ4-compressed block,

or null if level is 0 (store-only mode).

Throws

CompressionError with ErrorCode.INVALID_INPUT if

src.length exceeds LZ4_MAX_INPUT_SIZE.