\Drupal\strata\Codec ZstdPipeCodec

Zstandard through the `zstd` binary, for hosts without `ext-zstd`.

This exists because the extension is absent on many hosts and gzip costs 76% more stored bytes. It is explicitly NOT a per-frame codec: a process spawn dominates the work at frame sizes, and 1,000 separate zstd invocations were measured at 5.88 seconds - roughly 5.9 ms each against the sub-millisecond compression itself. PipeCodec carries that split and the process handling.

Frames it writes carry the same id and the same bytes as ZstdCodec's, so a bucket written on a host with the extension reads on a host with only the binary and the other way round.

Summary

Methods
Properties
Constants
id
levels
__construct
isAvailable
unavailableReason
supportsDictionary
compress
decompress
compressBatch
decompressBatch
No public properties found
No public constants found
binaryName
suffix
arguments
No protected properties found
No protected constants found
No private methods found
No private properties found
No private constants found

Methods

id()

id() : string

The stable identifier recorded in a frame header.

Returns

string —

A short lowercase token such as "zstd", "gzip" or "none".

levels()

levels() : array{min: int, max: int, default: int, fast: int, dense: int}

The compression levels this codec accepts.

Returns

array{min: int, max: int, default: int, fast: int, dense: int} —

The usable range, the default, the level to use on the flush path where throughput matters, and the level to use during compaction where ratio matters.

__construct()

__construct(string|null  $binaryPath = null, string|null  $scratchDirectory = null) : mixed

Constructs the codec.

Parameters

string|null $binaryPath

An explicit path to the binary, or NULL to search PATH and the common directories.

string|null $scratchDirectory

Directory for batch scratch files, or NULL for the system temporary directory.

Returns

mixed —

isAvailable()

isAvailable() : bool

Whether this codec can run on this host right now.

Returns

bool —

TRUE when every extension or binary the codec needs is present.

unavailableReason()

unavailableReason() : string|null

Why the codec is unavailable, for the settings form and hook_requirements().

Returns

string|null —

A short human-readable reason, or NULL when the codec is available.

supportsDictionary()

supportsDictionary() : bool

Whether the codec accepts a training dictionary.

Returns

bool —

TRUE when compress() and decompress() honour their $dictionary argument.

compress()

compress(string  $data, ?int  $level = null, ?string  $dictionary = null) : string

Compresses a buffer.

Parameters

string $data

The bytes to compress. An empty string compresses to an empty string, so that an absent payload never becomes a non-empty frame.

?int $level

A level within CompressionCodecInterface::levels(), or NULL for the default.

?string $dictionary

Raw dictionary bytes, or NULL. Ignored by codecs that report no dictionary support, so a caller never has to branch on it.

Returns

string —

The compressed bytes.

decompress()

decompress(string  $data, ?string  $dictionary = null) : string

Decompresses a buffer.

Parameters

string $data

The compressed bytes.

?string $dictionary

The same dictionary bytes used to compress, or NULL.

Returns

string —

The original bytes.

compressBatch()

compressBatch(list  $buffers, int|null  $level = null, string|null  $dictionary = null) : list<string>

Compresses many buffers in one process.

Parameters

list $buffers

The buffers to compress, in order.

int|null $level

A level within PipeCodec::levels(), or NULL for the default.

string|null $dictionary

Raw dictionary bytes, or NULL.

Throws

\RuntimeException

When the codec is unavailable, or the binary fails.

Returns

list

The compressed buffers, in the same order.

decompressBatch()

decompressBatch(list  $buffers, string|null  $dictionary = null) : list<string>

Decompresses many buffers in one process.

Parameters

list $buffers

The buffers to decompress, in order.

string|null $dictionary

The same dictionary bytes used to compress, or NULL.

Throws

\RuntimeException

When the codec is unavailable, or the binary fails.

Returns

list

The original buffers, in the same order.

binaryName()

binaryName() : string

The executable this codec drives, as it is named on the PATH.

Returns

string —

The file name, with no directory.

suffix()

suffix() : string

The extension the binary appends to a compressed file.

Returns

string —

The suffix, leading dot included.

arguments()

arguments(bool  $compressing, int  $level, string|null  $dictionaryPath) : list<string>

The flags one invocation runs with, before the input paths.

Parameters

bool $compressing

TRUE to compress, FALSE to decompress.

int $level

A level already brought into range by PipeCodec::clamp().

string|null $dictionaryPath

Where the dictionary was written, or NULL when there is none.

Returns

list

The arguments, without the binary itself.