$ show maennchen/ZipStream-PHP
ZipStream-PHP is a PHP library for dynamically streaming ZIP archives directly to the client or any output stream without writing to disk on the server. It provides a clean API via the `ZipStream` class, which accepts files as strings, paths, streams, PSR-7 streams, or callbacks. The library supports DEFLATE and STORE compression, ZIP64 extensions for large archives, zero-header mode for streaming efficiency, and simulation modes to calculate output size without generating the archive. The architecture is monolithic but well-modularized: the main ZipStream orchestrates file entries, each handled by an internal `File` class, and binary data packing is abstracted through `PackField`. External dependencies are minimal (ext-mbstring, ext-zlib, optional PSR-7 packages), making it lightweight and easy to integrate. The codebase demonstrates strong engineering with comprehensive unit tests, static analysis (Psalm level 1), coding style enforcement, and CI/CD pipelines covering multiple PHP versions and OS platforms. Notable design choices include the use of PHP stream wrappers for custom output (CallbackStreamWrapper) and a simulation mode that enables accurate content-length headers without reading entire streams. Exception classes are well-defined, and the entire public API is fully documented with attributes and inline PHPDoc. The project is actively maintained with frequent commits, up-to-date dependency management, and a clear versioning and support policy.
The LLM identified 2 files worth highlighting for reuse:
A PHP stream wrapper that forwards all written data to a user-defined callback function. It solves the common problem of routing stream output to arbitrary destinations (e.g., multiple files, progress tracking, or networking) without buffering everything in memory. The implementation is self-contained, registers a custom protocol (`zipcb`), and handles cleanup robustly. It can be extracted into any PHP project that needs to intercept stream writes, making it a highly reusable utility for testing, logging, or custom output handling.
A PHP stream wrapper designed for testing failure scenarios on resource operations. It allows injecting faults (e.g., failures on `stream_write`, `stream_seek`) by passing a list of function names via stream context. This enables systematic testing of error handling in code that uses PHP resources, without needing real broken hardware. The pattern is self-contained, can be extracted to any project's test suite, and demonstrates a robust approach to resource fault injection.