diff --git a/src/Microsoft.AspNetCore.Http.Extensions/StreamCopyOperation.cs b/src/Microsoft.AspNetCore.Http.Extensions/StreamCopyOperation.cs index ef81ac3baf..12067fef65 100644 --- a/src/Microsoft.AspNetCore.Http.Extensions/StreamCopyOperation.cs +++ b/src/Microsoft.AspNetCore.Http.Extensions/StreamCopyOperation.cs @@ -15,11 +15,29 @@ namespace Microsoft.AspNetCore.Http.Extensions { private const int DefaultBufferSize = 4096; - public static async Task CopyToAsync(Stream source, Stream destination, long? count, CancellationToken cancel) + /// Asynchronously reads the bytes from the source stream and writes them to another stream. + /// A task that represents the asynchronous copy operation. + /// The stream from which the contents will be copied. + /// The stream to which the contents of the current stream will be copied. + /// The count of bytes to be copied. + /// The token to monitor for cancellation requests. The default value is . + public static Task CopyToAsync(Stream source, Stream destination, long? count, CancellationToken cancel) + { + return CopyToAsync(source, destination, count, DefaultBufferSize, cancel); + } + + /// Asynchronously reads the bytes from the source stream and writes them to another stream, using a specified buffer size. + /// A task that represents the asynchronous copy operation. + /// The stream from which the contents will be copied. + /// The stream to which the contents of the current stream will be copied. + /// The count of bytes to be copied. + /// The size, in bytes, of the buffer. This value must be greater than zero. The default size is 4096. + /// The token to monitor for cancellation requests. The default value is . + public static async Task CopyToAsync(Stream source, Stream destination, long? count, int bufferSize, CancellationToken cancel) { long? bytesRemaining = count; - var buffer = ArrayPool.Shared.Rent(DefaultBufferSize); + var buffer = ArrayPool.Shared.Rent(bufferSize); try { Debug.Assert(source != null);