azjezz/psl
PSL is a modern, well-typed standard library for PHP 8.4+, inspired by HHVM’s HSL. It offers safer, predictable APIs for async, collections, networking, I/O, crypto, terminal UI, and robust data validation—replacing brittle built-ins with consistent alternatives.
[# Compression
The Compression component provides streaming compression and decompression abstractions for IO handles. It defines compressor and decompressor interfaces, and four handle decorators that transparently compress or decompress data as it flows through.
This component is an abstraction layer -- it does not include any compression algorithms. Concrete implementations (e.g. deflate, gzip, brotli, zstd) are provided by separate packages that implement CompressorInterface and DecompressorInterface.
Two interfaces define the compression contract:
CompressorInterface -- push(string $data): string to incrementally compress, finish(): string to finalize and resetDecompressorInterface -- push(string $data): string to incrementally decompress, finish(): string to finalize and resetAfter finish(), the instance resets to initial state and can be reused for a new stream. Compression and decompression are inherently stateful -- a single instance must not be used concurrently across multiple fibers or streams.
CompressingReadHandle and DecompressingReadHandle wrap a readable handle and transform data on read. Both implement ReadHandleInterface. Wrap with IO\Reader for buffered methods like readLine() and readUntil().
Both accept an optional $chunkSize parameter (default 8192) controlling how many bytes are read from the inner handle per iteration. Increase it for large file compression, decrease it to reduce memory usage per stream.
@example('io/compression-reader.php')
CompressingWriteHandle and DecompressingWriteHandle wrap a writable handle and transform data on write. Both implement BufferedWriteHandleInterface. Call flush() to finalize the handle and write any remaining buffered data.
@example('io/compression-writer.php')
flush() accepts an optional CancellationTokenInterface parameter, so you can set a timeout on the finalization when writing to network handles.
See src/Psl/Compression/ for the full API.
How can I help you explore Laravel packages today?