\Drupal\strata\Codec BrotliPipeCodec

Brotli through the `brotli` binary, for hosts without `ext-brotli`.

The reason to have it is reading, not writing. Brotli reaches the highest ratio Strata measured on Drupal-shaped data, so a site with the extension may well have a bucket full of brotli frames; without this, moving that site to a host whose PHP was built without ext-brotli makes every one of those frames unreadable and the backup stops being a backup. brotli ships in the base repositories of every mainstream distribution, so the binary is usually already there.

Like every PipeCodec it is registered for reading and bulk work only. It also loses the write path on merit: brotli at its top quality is 0.7 MB/s before a process spawn is added.

The CLI's -D takes a raw LZ77 dictionary, which is what brotli_compress() takes fourth, so the two produce and read each other's dictionary-coded frames.

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.