Skip to content

fix(bufiox): ReadBinary returns incorrect n#62

Merged
xiaost merged 1 commit into
mainfrom
fix/bufiox-read-binary
Feb 12, 2026
Merged

fix(bufiox): ReadBinary returns incorrect n#62
xiaost merged 1 commit into
mainfrom
fix/bufiox-read-binary

Conversation

@xiaost

@xiaost xiaost commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

Refactored DefaultReader internals and fixed a bug where ReadBinary returned an incorrect byte count n.

Key changes:

  • Merged bufreader.go and bufwriter.go into a single bufiox.go file (Reader + Writer interfaces).
  • Replaced readExpected with a standalone readAtLeast helper that follows io.ReadAtLeast semantics (returns io.ErrUnexpectedEOF on partial reads).
  • Added Buffered() method to return the number of bytes that can be read from the current buffer.
  • Simplified acquire for skip case, advance past buffered data before calling acquire in Skip.
  • Simplified acquire to return an error instead of a length, and added a panic guard against redundant calls.
  • Fixed ReadBinary direct-read path: previously sliced bs[:n:len(bs)] and reassigned n from readExpected, losing the already-copied count. Now it accumulates nn from readAtLeast into n correctly.
  • Added tests for Skip, ReadBinary, and Read covering buffer boundaries, reallocation, EOF, and data preservation.

@xiaost xiaost force-pushed the fix/bufiox-read-binary branch from d2bb70b to 4cf2648 Compare February 12, 2026 07:27
Comment thread .github/workflows/pr-check.yml Dismissed
ppzqh
ppzqh previously approved these changes Feb 12, 2026
Refactored DefaultReader internals and fixed a bug where ReadBinary returned an incorrect byte count n.

Key changes:
- Merged bufreader.go and bufwriter.go into a single bufiox.go file (Reader + Writer interfaces).
- Replaced readExpected with a standalone readAtLeast helper that follows io.ReadAtLeast semantics (returns io.ErrUnexpectedEOF on partial reads).
- Added Buffered() method to return the number of bytes that can be read from the current buffer.
- Simplified acquire for skip case, advance past buffered data before calling acquire in Skip.
- Simplified acquire to return an error instead of a length, and added a panic guard against redundant calls.
- Fixed ReadBinary direct-read path: previously sliced bs[:n:len(bs)] and reassigned n from readExpected, losing the already-copied count. Now it accumulates nn from readAtLeast into n correctly.
- Added tests for Skip, ReadBinary, and Read covering buffer boundaries, reallocation, EOF, and data preservation.
@xiaost xiaost merged commit 8a2e056 into main Feb 12, 2026
30 checks passed
@xiaost xiaost deleted the fix/bufiox-read-binary branch February 12, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants