ZipStream-PHP icon indicating copy to clipboard operation
ZipStream-PHP copied to clipboard

Add CallbackStreamWrapper for custom ZIP output (#199)

Open eyupcanakman opened this issue 9 months ago • 1 comments

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 the outputStream option.
  • 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

eyupcanakman avatar Jun 06 '25 16:06 eyupcanakman

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).

maennchen avatar Jun 06 '25 20:06 maennchen

@eyupcanakman Are you planning to finish this PR?

maennchen avatar Jul 15 '25 21:07 maennchen

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

eyupcanakman avatar Jul 16 '25 12:07 eyupcanakman