Skip to content

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

@mcclure

Description

@mcclure

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions