Add CallbackStreamWrapper for custom ZIP output (#199)
Summary
This PR introduces the CallbackStreamWrapper, a new stream wrapper (zipcb://) allowing ZIP output to be sent to any custom PHP callback function.
Why
- Streaming simultaneously to multiple destinations (e.g., files, logs, browser).
- Real-time progress tracking during archive creation.
- Performing safe, byte-stream-level data transformations without temporary files.
Requested originally in #199.
What changed
-
New class
ZipStream\Stream\CallbackStreamWrapper(zipcb://protocol).
CallbackStreamWrapper::open(callable $cb)returns a writable resource for theoutputStreamoption. -
Docs: updated
README.md,guides/Options.rst,guides/StreamOutput.rst. -
Tests: new
test/CallbackOutputTest.php(data integrity, multi-stream, error handling, stats, large chunks, progress).
Backward compatibility
No breaking changes. Existing code that passes a normal stream resource still works.
Closes #199
Thanks for the PR, this looks amazing ❤️
I’m off organizing a festival this week and will have a closer look next week (Wednesday or a bit later).
@eyupcanakman Are you planning to finish this PR?
Hi @maennchen,
Sorry for the delay. I have just pushed a new commit with your feedback. The progress example now calls reportProgress() instead of echo so the ZIP stream stays correct. The data transform example now uses PHP stream filters as you suggested.
Please let me know if you'd like any other changes