Skip to content

feat: Buffer readDiscard#7244

Open
turuslan wants to merge 3 commits into
denoland:mainfrom
turuslan:feature/buffer-read-discard
Open

feat: Buffer readDiscard#7244
turuslan wants to merge 3 commits into
denoland:mainfrom
turuslan:feature/buffer-read-discard

Conversation

@turuslan

@turuslan turuslan commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Buffer class is used by parsers.
Sometimes parser needs to advance read position without copying bytes.
For example, zero-copy parser peeks available bytes(), then consumes some of them and advances read position.

Buffer class hides read position as #off private field.
The only function that advances read position is read(p)/readSync(p), which accept buffer as argument.

// currently available workaround
function readDiscard(buf: Buffer, n: number) {
  buf.readSync({ byteLength: n, set() {} });
}

Go provides https://pkg.go.dev/bytes#Buffer.Next function, which advances read position without copying bytes.
This PR proposes readDiscard(n) (please suggest better name), which doesn't return value.

There is truncate(n) function, which does opposite, it keeps "first N bytes", not "after N bytes"

Signed-off-by: turuslan <turuslan.devbox@gmail.com>
@github-actions github-actions Bot added the io label Jul 20, 2026
@turuslan turuslan changed the title Buffer readDiscard feat Buffer readDiscard Jul 20, 2026
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.00%. Comparing base (ad7c87b) to head (cd66a8c).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7244    +/-   ##
========================================
  Coverage   95.00%   95.00%            
========================================
  Files         617      617            
  Lines       51674    51428   -246     
  Branches     9326     9279    -47     
========================================
- Hits        49093    48860   -233     
+ Misses       2038     2029     -9     
+ Partials      543      539     -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@turuslan turuslan changed the title feat Buffer readDiscard feat: Buffer readDiscard Jul 20, 2026
turuslan added 2 commits July 20, 2026 09:03
Signed-off-by: turuslan <turuslan.devbox@gmail.com>
Signed-off-by: turuslan <turuslan.devbox@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant