lz4DecompressBlock

private fnsize_t lz4DecompressBlock(const(ubyte)[] src, ubyte[] dst)

Decompress a single LZ4 block into a caller‑provided buffer.

The function implements the standard LZ4 block format:

  1. Read a token byte.
  2. Extract literal length from the high nibble, extending it with

trailing bytes of value 255 as needed.

  1. Copy that many literal bytes from the input to the output.
  2. If the input is exhausted, stop (final literals).
  3. Otherwise, read a 16‑bit little‑endian offset and a match length

from the low nibble of the token (extended by 255‑valued bytes as for literals) plus LZ4_MIN_MATCH.

  1. Copy matchLen bytes from the already‑produced output, at distance

offset.

  1. Repeat from step 1 until the input buffer is exhausted.

The implementation performs strict bounds checks and never writes past dst.length or reads past src.length.

Parameters

srcLZ4 block to decode.
dstDestination buffer; must be large enough to hold the decompressed data.

Returns

Number of bytes written to dst.

Throws

- CompressionError with ErrorCode.TRUNCATED if the input block

ends prematurely (e.g. while reading literals, offset, or length extensions).

  • CompressionError with ErrorCode.DATA_ERROR if an invalid

offset or other structural inconsistency is encountered.