Skip to content

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

Open

Description

@joelverhagen

Problem Description

When using mitmdump --save-stream-file to capture flows over long periods or high-traffic proxying, the resulting files can grow very large. There's no built-in way to compress them on the fly - users must compress after the fact, which doesn't work well with strftime-rotated files or disk space constraints during capture.

Proposal

Add a --set save_stream_compression=gz|bz2|xz option that compresses stream files on the fly. Optionally accepts a level (e.g. gz=9). On the read side, auto-detect compressed files via magic bytes so -r, view.flows.load, replay addons, and the Python API transparently read gz/bz2/xz files without any extra flags.

Alternatives

  • Infer compression from file extension (.gz) - rejected because this would be a breaking change if someone happens to use these extensions today for uncompressed files.
  • Post-hoc compression - wastes disk I/O and doesn't help with disk space constraints during capture.

Additional context

I have a working implementation with tests ready to open as a PR.

Activity

  1. added
    kind/feature
    on Jun 20, 2026
  2. mhils commented on Jul 17, 2026

    @mhils
    Member

    I think this is a reasonable feature request overall, but the solution seems overengineered. Can we agree on one compression algorithm (zstandard?) without any configurability?

  3. joelverhagen commented on Jul 17, 2026

    @joelverhagen
    Author

    Sure! I don't have a strong feeling about which compression to use, although I found gzip worked by well for my own integration. I see zstd is in Python BCL starting 3.14 (https://peps.python.org/pep-0784/). Can we assume users of this feature will always have Python 3.14? I see in this:

    requires-python = ">=3.12"

    So I am thinking maybe the feature would have to be disabled for Python 3.12 and 3.13.

    I'm happy to update the PR in this direction if it sounds right to you.

  4. mhils commented on Jul 17, 2026

    @mhils
    Member

    We depend on the zstandard package already anyway. Let's use that, we can migrate everything to stdlib once we drop 3.13. :)

  5. joelverhagen commented on Jul 18, 2026

    @joelverhagen
    Author

    It is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions