ZipStream-PHP
Stream ZIP archives directly to the browser or any PSR-7 stream, no temp files needed.
Repository Health
Technical Analysis
ZipStream-PHP (maennchen/zipstream-php) is a fast, simple streaming ZIP library for PHP. Instead of building a ZIP file on disk and then serving it, it generates the archive on the fly and streams it directly to the client, a PSR-7 stream, or an S3 bucket, which is faster and avoids temporary storage.
The library exposes a ZipStream object you feed files, strings, or streams into, and it handles the ZIP format details including large-file support via Zip64, multiple compression methods, and correct central-directory and header generation. It is widely used for on-demand multi-file downloads in web applications.
What You Get
- A ZipStream object for adding files, strings, and streams to an archive on the fly
- Direct streaming output to the browser, a PSR-7 stream, or S3-compatible storage
- Zip64 support for archives and entries larger than 4 GB
- Selectable compression methods (store or deflate) per entry
Common Use Cases
- Offering a bundled ZIP download of many user files without staging them on disk
- Streaming large archives that exceed available temp storage or memory
- Zipping objects read directly from S3 or another remote stream
Under The Hood
Architecture - The public entry point is ZipStream\ZipStream (src/ZipStream.php); callers add entries and the library writes ZIP structures directly to the configured output. The src tree models the ZIP format explicitly: LocalFileHeader, CentralDirectoryFileHeader, DataDescriptor, EndOfCentralDirectory, GeneralPurposeBitFlag, CompressionMethod, and a Zip64 subpackage for large-file records, with PackField handling binary field packing and a Stream namespace bridging PSR-7 and raw streams. Output is emitted incrementally so nothing is buffered to disk.
Tech Stack - Modern PHP using named arguments and enums (CompressionMethod, OperationMode, Version), packaged via Composer, tested with PHPUnit, statically analysed with Psalm, and documented with phpDocumentor. It integrates with PSR-7 streams for interoperability.
Code Quality - The project is mature and health-conscious: OpenSSF Best Practices badge, an OpenSSF Scorecard, Coveralls coverage, a test/ suite, and a guides/ directory. Each ZIP structure is its own well-named class, making the binary format approachable and the code auditable.
API Design - Construction uses readable named arguments (new ZipStream(outputName: ‘example.zip’, …)) and a small method surface to add files and streams, so common downloads take only a few lines. The main conceptual load is understanding streaming output semantics rather than the API, keeping the learning curve moderate.