Skip to content

Add CallbackStreamWrapper for custom ZIP output #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 17, 2025

Conversation

eyupcanakman
Copy link
Contributor

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

@Copilot Copilot AI review requested due to automatic review settings June 6, 2025 16:03
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new CallbackStreamWrapper to allow ZIP output to be sent to any custom PHP callback, enabling streaming to multiple destinations and real-time progress tracking.

  • Introduces the CallbackStreamWrapper class with the zipcb:// protocol support
  • Adds comprehensive tests in CallbackOutputTest.php covering data forwarding, error handling, and stream statistics
  • Updates documentation in README.md, Options.rst, and StreamOutput.rst to cover usage details

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/CallbackOutputTest.php New tests validating the callback stream behavior and error cases
src/Stream/CallbackStreamWrapper.php Implements the callback stream wrapper class for ZIP streaming
guides/StreamOutput.rst Added examples for using CallbackStreamWrapper in documentation
guides/Options.rst Documents CallbackStreamWrapper as an option for outputStream
README.md Demonstrates CallbackStreamWrapper usage with code examples

@maennchen
Copy link
Owner

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 maennchen changed the title Add CallbackStreamWrapper for custom ZIP output (#199) Add CallbackStreamWrapper for custom ZIP output Jul 15, 2025
@maennchen
Copy link
Owner

@eyupcanakman Are you planning to finish this PR?

- Replace progress echo with reportProgress() function call in Example 2
- Replace callback-based base64 with PHP stream filters in Example 3
@eyupcanakman
Copy link
Contributor Author

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

@maennchen maennchen merged commit e8b4b8d into maennchen:main Jul 17, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support callback for output
2 participants