\Drupal\strata\Codec ZstdCodec

Zstandard through `ext-zstd`.

The codec Strata is designed around. Measured on Drupal-shaped data in 8 KiB frames: 3.71x alone, and 6.20x with a trained dictionary - 76% fewer stored bytes than gzip at the same frame size. Level 1 runs at 287 MB/s and level 19 at 2.6 MB/s, which is why the flush path and the compaction path use different levels rather than one compromise.

The extension is absent on many hosts, so ZstdCodec::isAvailable() gates every entry point. ZstdPipeCodec covers the same algorithm through the zstd binary for bulk work when the extension is missing.

Dictionary support is probed per function, because the extension has shipped more than one spelling of the dictionary API and a host can have the base functions without them.

Summary

Methods
Properties
Constants
id
isAvailable
unavailableReason
supportsDictionary
levels
compress
decompress
No public properties found
No public constants found
No protected methods found
No protected properties found
No protected constants found
clamp
assertAvailable
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".

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.

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.

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.

clamp()

clamp(int|null  $level) : int

Brings a requested level into the supported range.

Parameters

int|null $level

The requested level, or NULL for the default.

Returns

int —

A level this codec accepts.

assertAvailable()

assertAvailable() : void

Guards every entry point.

Throws

\RuntimeException

When ext-zstd is not loaded.

Returns

void —