Skip to content
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

Feature request: "Give me a buffer of any length" #103

Open
mcclure opened this issue Jul 19, 2021 · 2 comments
Open

Feature request: "Give me a buffer of any length" #103

mcclure opened this issue Jul 19, 2021 · 2 comments

Comments

@mcclure
Copy link

mcclure commented Jul 19, 2021

So I am using a third party library which returns your BufferList. My own code has an existing "buffering" mechanism which largely reproduces the functions of BufferList— I have a readBytes(dst:Uint8Array, bytesMax:number) which abstracts over several types of data stream. I am now adding BufferLists as a stream that can be read from.

So what I want to work with my code is some way to get "some uint8array" from a BufferList. Your docs say there is slice, but they also say:

If the requested range spans a single internal buffer then a slice of that buffer will be returned which shares the original memory range of that Buffer. If the range spans multiple buffers then copy operations will likely occur to give you a uniform Buffer.

What I want is the longest possible buffer which does not involve copying. slice() can return a buffer without copying if I request a slice of the size of the first internal buffer, but it doesn't give me a way of asking what the internal buffer sizes are.

Expected behavior: There should be a readBuffer or readArbitraryBuffer which pops off the first internal buffer and returns it. The documented semantics could be something like "returns the longest buffer which can currently be returned without copying". This wording would allow for future refactoring or for cases where the user has already read several bytes out of an internal buffer (which means a slice() of the remainder of the internal buffer is needed).

@mcollina
Copy link
Collaborator

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@mcclure
Copy link
Author

mcclure commented Jul 19, 2021

Sure, I'll give that a shot tomorrow.

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

No branches or pull requests

2 participants