Skip to content

🧪 Verify DeflateEncoder::flush() and fix buffer size calculation#386

Merged
404Setup merged 1 commit intomainfrom
test-deflate-encoder-flush-6308347625370725793
Feb 24, 2026
Merged

🧪 Verify DeflateEncoder::flush() and fix buffer size calculation#386
404Setup merged 1 commit intomainfrom
test-deflate-encoder-flush-6308347625370725793

Conversation

@404Setup
Copy link
Copy Markdown
Owner

This PR adds a test case to verify the behavior of DeflateEncoder::flush(), ensuring that it correctly compresses buffered data and flushes the underlying writer.

During the implementation of the test, a bug was discovered where DeflateEncoder would fail to flush small amounts of data (e.g., "Hello World") because the output buffer size calculation (deflate_compress_bound) did not account for the additional 5-byte overhead required by the FlushMode::Sync block marker (00 00 FF FF + alignment).

This PR fixes the issue by reserving an additional 5 bytes when FlushMode::Sync is used (i.e., when the block is not the final block).

Changes:

  • tests/stream_test.rs: Added test_encoder_flush and test_encoder_flush_error.
  • src/stream.rs: Increased buffer reservation by 5 bytes for non-final blocks in both single-threaded and parallel compression paths.

Coverage:

  • Verifies DeflateEncoder::flush() succeeds.
  • Verifies data is written to the underlying writer.
  • Verifies underlying writer's flush() is called.
  • Verifies error propagation from underlying writer.

PR created automatically by Jules for task 6308347625370725793 started by @404Setup

- Added `test_encoder_flush` and `test_encoder_flush_error` to `tests/stream_test.rs`.
- Implemented `FlushTrackingWriter` and `ErrorFlushWriter` helpers to verify underlying writer behavior.
- Fixed a bug in `src/stream.rs` where `deflate_compress_bound` did not account for the 5-byte overhead of `FlushMode::Sync` blocks (used in non-final chunks), which caused `flush()` to fail on small inputs.
- Verified that `flush()` propagates data to the underlying writer and calls its `flush()` method.

Co-authored-by: 404Setup <[email protected]>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@404Setup 404Setup merged commit d15ac05 into main Feb 24, 2026
1 check passed
@404Setup 404Setup deleted the test-deflate-encoder-flush-6308347625370725793 branch February 24, 2026 14:01
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.

1 participant