Skip to content

Feature request: Create a Stream that reads from a ReadOnlySequence<byte> #27156

Open
@AArnott

Description

@AArnott

I'm re-implementing a protocol in terms of System.IO.Pipelines and striving for minimal allocations, especially of large objects. As part of this, I no longer have to allocate a large array for the entire message, since I read it as it comes in via PipeReader.

At some point I get to the main "content" which I need to deserialize. The deserialization API accepts a TextReader, which I plan to use a StreamReader for. But for that I need a Stream that will read from the ReadOnlySequence<byte> that I got from the PipeReader. I'm planning on writing this up myself in Nerdbank.Streams and exposing it as an Stream ReadOnlySequence<byte>.AsStream() extension method.

Should this be a built-in feature of .NET? I'm imagining perhaps a ReadOnlyMemoryStream class with constructors that accepts ReadOnlyMemory<byte> or ReadOnlySequence<byte> .

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Memory

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions