RecyclableMemoryStream.CopyToAsync method

March 12, 2021 · View on GitHub

Asynchronously reads all the bytes from the current position in this stream and writes them to another stream.

public override Task CopyToAsync(Stream destination, int bufferSize, 
    CancellationToken cancellationToken)
parameterdescription
destinationThe stream to which the contents of the current stream will be copied.
bufferSizeThis parameter is ignored.
cancellationTokenThe token to monitor for cancellation requests.

Return Value

A task that represents the asynchronous copy operation.

Exceptions

exceptioncondition
ArgumentNullExceptiondestination is null.
ObjectDisposedExceptionEither the current stream or the destination stream is disposed.
NotSupportedExceptionThe current stream does not support reading, or the destination stream does not support writing.

Remarks

Similarly to MemoryStream's behavior, CopyToAsync will adjust the source stream's position by the number of bytes written to the destination stream, as a Read would do.

See Also