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

PipeReader CopyToAsync an overload to copy To IBufferWriter<byte> #2062

Open
oliverjanik opened this issue Jan 23, 2020 · 3 comments
Open

PipeReader CopyToAsync an overload to copy To IBufferWriter<byte> #2062

oliverjanik opened this issue Jan 23, 2020 · 3 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.IO.Pipelines backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity
Milestone

Comments

@oliverjanik
Copy link

At the moment (net core 3.1.1) PipeReader.CopyToAsync has 2 overloads:

  • copy to Stream
  • copy to PipeWriter (which implements IBufferWriter<byte>)

https://docs.microsoft.com/en-us/dotnet/api/system.io.pipelines.pipereader.copytoasync

I'm trying to copy PipeReader into ArrayBufferWriter<byte> which seems like a common use-case and there's no direct way to do it.

Of course I could use a MemoryStream but where's the fun in that?

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.IO untriaged New issue has not been triaged by the area owner labels Jan 23, 2020
@jaredpar jaredpar changed the title PireReader CopyToAsync an overload to copy To IBufferWriter<byte> PipeReader CopyToAsync an overload to copy To IBufferWriter<byte> Jan 23, 2020
@davidfowl davidfowl added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jan 23, 2020
@manandre
Copy link
Contributor

manandre commented Jan 25, 2020

In next release, a new Stream.CopyToAsync overload will be available as described in https://github.com/dotnet/corefx/issues/21472

public virtual Task CopyToAsync(Func<ReadOnlyMemory<byte>, object?, CancellationToken, ValueTask> callback, object? state, int bufferSize, CancellationToken cancellationToken)

Enabling this type of code:

await pipeReader
    .AsStream()
    .CopyToAsync((memory, state, _) => 
    {
        ((IBufferWriter<byte>)state).Write(memory.Span);
        return default;
    },
    state: bufferWriter,
    bufferSize: 4096,
    cancellationToken: default); 

Would it fit your need?

@oliverjanik
Copy link
Author

Nah, I'm suggesting a convenience function. Your solution is longer than using ReadAsync in a while loop.

As a side note, is there any guidance on when to use streams vs the new pipelines?

@BrennanConroy BrennanConroy added this to the Future milestone Jul 8, 2020
@halter73 halter73 removed the untriaged New issue has not been triaged by the area owner label Jul 8, 2020
Copy link
Contributor

Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

This process is part of our issue cleanup automation.

@dotnet-policy-service dotnet-policy-service bot added backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.IO.Pipelines backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity
Projects
None yet
Development

No branches or pull requests

7 participants