-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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: Create a Stream that reads from a ReadOnlySequence<byte> #27156
Comments
Related #26676 #25087 |
@AArnott did you get this implemented in your own package? because I've just reached a point where it would be really useful. |
FWIW I think this should exist, but it ends up being a heap allocation. So It kinda sucks. |
Allocation of the stream? presuming that I can get a section of the input sequence using Slice() I can stand a few allocs to create a container for that to avoid needing to copy the contents of the buffers. For example i'll have a situation where there will 2Mib+ of compressed data in a pipe surrounded by some framing data. I want to identify the frame and payload limits then push out the payload section using a ROS slice, wrap that in decompression (and possible possibly crypto) stream and then use that as input to a streamed database parameter. |
For big buffers I agree. This was a significant amount of allocations if you're sending lots of data. |
@AArnott Can you propose an API? I'd like to add this for 3.0, but we need an API proposal here. It gels nicely with the other APIs we'd like to add to 3.0 |
Whatever we do here, I'd like to see it done in conjunction with https://github.com/dotnet/corefx/issues/22404, which is about creating streams for |
How do you all feel about The only time it doesn't work is when I need to expose special members. The only one I can think of now is if we create a (writable) stream over |
Seems reasonable. |
Would it be possible to include this in .NET 6? |
💯 |
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 aStreamReader
for. But for that I need aStream
that will read from theReadOnlySequence<byte>
that I got from thePipeReader
. I'm planning on writing this up myself inNerdbank.Streams
and exposing it as anStream ReadOnlySequence<byte>.AsStream()
extension method.Should this be a built-in feature of .NET? I'm imagining perhaps a
ReadOnlyMemoryStream
class with constructors that acceptsReadOnlyMemory<byte>
orReadOnlySequence<byte>
.The text was updated successfully, but these errors were encountered: