-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
buffer: create relative reading methods #58295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Not sure how others feel about this — it adds a bit of complexity to |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #58295 +/- ##
==========================================
+ Coverage 90.19% 90.42% +0.23%
==========================================
Files 631 635 +4
Lines 186690 188219 +1529
Branches 36665 38967 +2302
==========================================
+ Hits 168380 170200 +1820
+ Misses 11123 10786 -337
- Partials 7187 7233 +46
🚀 New features to boost your workflow:
|
function reset() { | ||
this.readerIndex = 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could be a seek function that one can set any index
function reset() { | |
this.readerIndex = 0; | |
} | |
function seek(n) { | |
this.readerIndex = n; | |
} |
It seems consistent with the current interface already. Pinging @nodejs/buffer since they will have a better opinion on this (and the bot didn't ping them as I think it should). |
It would be good to describe these newly added features in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I see that it is making it easier for some use cases / nicer to read for users to use these APIs, it would also be just as easy for someone to implement such helper on their side. Due to that, I don't think we have a strong enough reason for supporting the big amount of added methods. They would need to be documented and updated as well over time.
I won't block and wait for other collaborators to chime in. If there is support by others, great, if there is no support in a couple of weeks, I would go ahead and suggest to close it.
I think part of the motivation here is that lots of folks end up implementing the helper on this and it would be good to just have something built-in that works. That said, I don't think extending the
|
I agree with @jasnell. As a reference, here is the API that I came up with (mostly to read and write binary data formats): https://github.com/image-js/iobuffer |
+1, I can work on this. It's what is suggested in #58348 (comment). |
Introduces relative reading methods to
Buffer
, inspired by similar abstractions in Java and Rust's ByteBuffer. These methods maintain an internal reader index to support sequential reads without manually tracking offsets.Related #58348