Raw deflate with a preset dictionary, from ext-zlib on any ordinary host.
The dictionary is worth more than the algorithm here: measured on Drupal-shaped data, gzip -9
reaches 3.52x standalone and delta coding against the previous version reaches 63.70x. Delta
coding is "hand the previous version to the compressor as its dictionary", so every codec
reporting no dictionary support meant every frame anchored and the store kept full copies.
gzdeflate() cannot carry a dictionary but deflate_init() can. The incremental zlib API has
taken a dictionary option since PHP 7.0, and ext-zlib is already a hard requirement of this
package, so a VPS, a container and a shared host all get this codec with nothing installed. That
is the whole mechanism; ext-zstd, ext-brotli and a zstd binary stay optional upgrades.
The host bridge is a fallback for runtimes that lack the incremental API, not the mechanism.
A PHP built for a JavaScript host - a Worker deployment compiled to WASM - can ship without
deflate_init() while still being able to deflate; such a host installs a function this codec
calls instead. Neither path changes the bytes: both emit raw deflate, so a frame written through
one is readable through the other.
A host with neither leaves this codec unavailable and the registry falls back, the same contract
every other codec here follows. id() is stable and recorded in the frame header, so a store
stays readable in the sense that matters: a host that cannot decode reports why rather than
returning damaged bytes.
The host function used when the incremental zlib API is absent.
Named for the one runtime known to install it. A different host wanting this path installs a
function under this name; nothing else about the codec changes.
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.
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.
A NULL or empty dictionary is a plain deflate rather than an error: the caller decides whether
a frame anchors, and refusing here would make the anchor frame of every chain fail.
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.
Raises rather than returning partial output. A frame decompressed against the WRONG dictionary
does not error in zlib, it produces plausible garbage, so the caller has to hand back the same
bytes it compressed with; the chain in ObjectStore is what guarantees that.
Parameters
string
$data
The compressed bytes.
?string
$dictionary
The same dictionary bytes used to compress, or NULL.
Returns
string
—
The original bytes.
native()
native(string $data, string $dictionary, int $level) : string|false
Deflates against a preset dictionary using ext-zlib.
ZLIB_ENCODING_RAW rather than the zlib container, so the output is the same raw deflate stream
gzdeflate() produces and an anchor frame and a delta frame stay one format.
Inflates against a preset dictionary using ext-zlib.
Parameters
string
$data
The bytes to expand.
string
$dictionary
The preset dictionary the bytes were compressed against.
Returns
string|false
—
The original bytes, or FALSE.
bridge()
bridge(string $op, string $data, string $dictionary, int $level) : string|false
Calls the host function without naming it at compile time.
Only reached on a host without the incremental zlib API. No presence check here: the callers
pick this path precisely because the native one is absent, and assertAvailable() has already
established that one of the two exists. stubs/cfw.php is what gives the analyser the
signature, the same way the extension stubs beside it do.
Parameters
string
$op
Either "deflate" or "inflate".
string
$data
The bytes to transform.
string
$dictionary
The preset dictionary.
int
$level
The compression level; ignored when inflating.
Returns
string|false
—
The transformed bytes, or FALSE.
clamp()
clamp(int|null $level) : int
Brings a requested level into the supported range.