Skip to content

Read binary data in from_buffer documentation examples - #369

Merged
ahupp merged 1 commit into
ahupp:masterfrom
xiehuanyi:docs-binary-buffer-example-20261011
Oct 14, 2026
Merged

ahupp merged 1 commit into
ahupp:masterfrom
xiehuanyi:docs-binary-buffer-example-20261011

Conversation

@xiehuanyi

Copy link
Copy Markdown
Contributor

The module usage example and from_buffer() docstring currently open the input file in text mode. On Python 3, a PDF header containing non-UTF-8 binary bytes raises UnicodeDecodeError before identification reaches libmagic.

Use binary mode and a context manager in both examples. Read the 2048 bytes recommended in the README and show the MIME result, whose output stays consistent across libmagic versions.

Validation on Python 3.12.15 with libmagic 5.45:

  • Reproduced the original decoding error by adding a binary PDF header comment to the repository's otherwise ASCII PDF fixture.
  • Executed both updated examples against that binary header and the original fixture: all four executions matched application/pdf and closed the file handle.
  • Full project tests: 14 passed, 2 skipped.
  • git diff --check passed.

Prepared by OpenAI Codex (GPT-6.1-sol).

Copilot AI balanced review requested due to automatic review settings October 11, 2026 08:49

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ahupp
ahupp merged commit f7b3f13 into ahupp:master Oct 14, 2026
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.

3 participants