Skip to content

Add on-the-fly zstandard compression for --save-stream-file - #8287

Open
joelverhagen wants to merge 14 commits into
mitmproxy:mainfrom
joelverhagen:joelverhagen/compressed-stream-file
Open

joelverhagen wants to merge 14 commits into
mitmproxy:mainfrom
joelverhagen:joelverhagen/compressed-stream-file

Conversation

@joelverhagen

@joelverhagen joelverhagen commented Jun 20, 2026 •

Copy link
Copy Markdown

Description

Closes #8286.

Adds a save_stream_compress boolean option that compresses stream files on the fly using zstandard.

On the read side, FlowReader auto-detects zstandard-compressed files via magic bytes — no extra flags needed. This works transparently with -r, view.flows.load, replay, and read_flows_from_paths().

Write side:

  • New save_stream_compress option (bool, default false)
  • Works with strftime rotation and append mode (+ prefix)
  • Guards against appending compressed data to uncompressed files (and vice versa)

Read side:

  • FlowReader sniffs the first 4 bytes for zstd magic and wraps in a decompressor transparently
  • Graceful error handling for corrupt compressed files (ZstdError -> FlowReadException)

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG

@joelverhagen
joelverhagen force-pushed the joelverhagen/compressed-stream-file branch from 1241530 to d88addc Compare July 18, 2026 04:32

@mhils mhils left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks slopped and not integrated into what's already there. FlowReader needs to support zstd instead of adding open_flow_file/read_flows_from_paths wrappers that complicate control flow.

Comment thread mitmproxy/addons/save.py Resolved
Comment thread test/mitmproxy/addons/test_save.py Resolved
@joelverhagen

Copy link
Copy Markdown
Author

This looks slopped and not integrated into what's already there. FlowReader needs to support zstd instead of adding open_flow_file/read_flows_from_paths wrappers that complicate control flow.

read_flows_from_paths is pre-existing, but I'll try out what you're suggesting.

@joelverhagen

Copy link
Copy Markdown
Author

I didn't eliminate the read_flows_from_paths since it was pre-existing but FlowReader now handles the zstd internally. I also improved the error handling when a the user attempts to mix uncompressed and compressed in the same append file.

@joelverhagen joelverhagen changed the title Add on-the-fly compression support for --save-stream-file Add on-the-fly zstandard compression for --save-stream-file Jul 26, 2026

This branch has not been deployed

No deployments
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.

Add on-the-fly compression support for --save-stream-file

2 participants