Repository navigation
feat: implement per-token lz4 frame flush - #2977
Merged
Merged
Conversation
Add flush() methods to CountingLz4Encoder and CountingZstdEncoder that emit all buffered data as decompressible output, matching zlib's Z_SYNC_FLUSH semantics. This enables the receiver to decompress tokens incrementally without waiting for stream finalization. The LZ4 flush delegates to FrameEncoder::flush() which writes any buffered uncompressed data as a complete LZ4 block. The zstd flush delegates to ZstdEncoder::flush() which triggers a zstd flush operation. Both methods are called by CompressedWriter::flush_compressed() at token boundaries, mirroring upstream rsync's per-token flush pattern in token.c:send_deflated_token(). Includes comprehensive tests verifying flush emits compressed data, flush-then-finish produces valid streams, multiple flush cycles round-trip correctly, and empty flush is a safe no-op.
oferchen
added a commit
that referenced
this pull request
May 1, 2026
Add flush() methods to CountingLz4Encoder and CountingZstdEncoder that emit all buffered data as decompressible output, matching zlib's Z_SYNC_FLUSH semantics. This enables the receiver to decompress tokens incrementally without waiting for stream finalization. The LZ4 flush delegates to FrameEncoder::flush() which writes any buffered uncompressed data as a complete LZ4 block. The zstd flush delegates to ZstdEncoder::flush() which triggers a zstd flush operation. Both methods are called by CompressedWriter::flush_compressed() at token boundaries, mirroring upstream rsync's per-token flush pattern in token.c:send_deflated_token(). Includes comprehensive tests verifying flush emits compressed data, flush-then-finish produces valid streams, multiple flush cycles round-trip correctly, and empty flush is a safe no-op.
oferchen
added a commit
that referenced
this pull request
May 5, 2026
Add flush() methods to CountingLz4Encoder and CountingZstdEncoder that emit all buffered data as decompressible output, matching zlib's Z_SYNC_FLUSH semantics. This enables the receiver to decompress tokens incrementally without waiting for stream finalization. The LZ4 flush delegates to FrameEncoder::flush() which writes any buffered uncompressed data as a complete LZ4 block. The zstd flush delegates to ZstdEncoder::flush() which triggers a zstd flush operation. Both methods are called by CompressedWriter::flush_compressed() at token boundaries, mirroring upstream rsync's per-token flush pattern in token.c:send_deflated_token(). Includes comprehensive tests verifying flush emits compressed data, flush-then-finish produces valid streams, multiple flush cycles round-trip correctly, and empty flush is a safe no-op.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Context
Like zlib's Z_SYNC_FLUSH, lz4 and zstd compression need per-token flush to allow incremental decompression. Without flush methods on the counting encoder wrappers, the CompressedWriter cannot materialize buffered compressed data at token boundaries, preventing the receiver from decompressing tokens as they arrive.
The zlib CountingZlibEncoder already had this via its Write trait impl (where flush() triggers Z_SYNC_FLUSH). The lz4 and zstd encoders were missing this capability.
Test plan