Skip to content

gh-155286: Write a valid empty zstd archive - #155342

Open
RealBhupesh wants to merge 1 commit into
python:mainfrom
RealBhupesh:agent/gh-155286-empty-zstd-archive
Open

gh-155286: Write a valid empty zstd archive#155342
RealBhupesh wants to merge 1 commit into
python:mainfrom
RealBhupesh:agent/gh-155286-empty-zstd-archive

Conversation

@RealBhupesh

@RealBhupesh RealBhupesh commented Aug 7, 2026

Copy link
Copy Markdown

Fixes #155286.

Summary:

  • Emit a valid empty Zstandard frame when a w/x ZstdFile is closed without writes.
  • Preserve append-mode behavior when no new data is written.

Tests:

  • ./python.exe -m test test_zstd (119 tests)

@python-cla-bot

python-cla-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 75d82ce9a2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

self._mode = _MODE_WRITE
# Do not add an empty frame when closing an existing archive in
# append mode without writing anything.
self._write_started = mode == 'a'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Emit a frame for newly created append targets

When ZstdFile(path, "a") creates a nonexistent file, or opens an existing zero-byte file, setting _write_started solely from the mode makes close() short-circuit because a new compressor's last_mode is already FLUSH_FRAME. With no writes, the target therefore remains a zero-byte, invalid Zstandard archive—the same failure this change fixes for w and x. Preserve no-op behavior only when the append target already contains archive data.

Useful? React with 👍 / 👎.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compression.zstd produces a broken archive if nothing is written

1 participant