lib/Task-Parallel-Library/StreamExtensions.cs
/// <summary>
/// Asynchronously writes a sequence of bytes to a stream and advances the position within the stream by the number of bytes written.
/// </summary>
/// <remarks>
/// Use the <see cref="Stream.CanWrite"/> property to determine whether the stream instance supports writing.
/// </remarks>
/// <param name="stream">The stream to write data to.</param>
/// <param name="buffer">The buffer to read the data from.</param>
/// <param name="offset">The zero-based byte offset in buffer from which to begin copying bytes to the stream.</param>
/// <param name="count">The maximum number of bytes to write.</param>
/// <returns>
/// A task that represents the asynchronous write operation.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <para>If <paramref name="stream"/> is <see langword="null"/>.</para>
/// <para>-or-</para>
/// <para>If <paramref name="buffer"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <para>If <paramref name="offset"/> is negative.</para>
/// <para>-or-</para>
/// <para>If <paramref name="count"/> is negative.</para>
/// </exception>
/// <exception cref="ArgumentException">
/// If the sum of <paramref name="offset"/> and <paramref name="count"/> is larger than the buffer length.
/// </exception>
/// <exception cref="NotSupportedException">If <paramref name="stream"/> does not support writing.</exception>
/// <exception cref="ObjectDisposedException">If <paramref name="stream"/> has been disposed.</exception>
/// <exception cref="InvalidOperationException">If <paramref name="stream"/> is currently in use by a previous write operation.</exception>
Asynchronously writes a sequence of bytes to a stream and advances the position within the stream by the number of bytes written.
Asynchronously writes a sequence of bytes to a stream and advances the position within the stream by the number of bytes written .
public static Task WriteAsync(this Stream stream, byte[] buffer, int offset, int count)
        {
            #if NET45PLUS
            if (stream == null)
            throw new ArgumentNullException("stream");
            return stream.WriteAsync(buffer, offset, count);
            #else
            return WriteAsync(stream, buffer, offset, count, CancellationToken.None);
            #endif
        }
public static Task WriteAsync ( this Stream stream , byte [ ] buffer , int offset , int count ) { if NET45PLUS if ( stream == null ) throw new ArgumentNullException ( " " ) ; return stream . WriteAsync ( buffer , offset , count ) ; else return WriteAsync ( stream , buffer , offset , count , CancellationToken . None ) ; endif }
Asynchronously writes a sequence of bytes to a stream and advances the position within the stream by the number of bytes written.
Asynchronously writes a sequence of bytes to a stream and advances the position within the stream by the number of bytes written .
// This code requires the `Stream` class provide an implementation of `WriteAsync`. The unit tests will // detect any case where this results in a stack overflow.
A task that represents the asynchronous write operation.
A task that represents the asynchronous write operation .
If  is .-or-If  is .
If is . - or - If is .
If  is negative.-or-If  is negative.
If is negative . - or - If is negative .
If the sum of  and  is larger than the buffer length.
If the sum of and is larger than the buffer length .
If  does not support writing.
If does not support writing .
If  has been disposed.
If has been disposed .
If  is currently in use by a previous write operation.
If is currently in use by a previous write operation .
Stream
this
buffer
byte[]
The buffer to read the data from.
The buffer to read the data from .
offset
int
The zero-based byte offset in buffer from which to begin copying bytes to the stream.
The zero - based byte offset in buffer from which to begin copying bytes to the stream .
count
int
The maximum number of bytes to write.
The maximum number of bytes to write .
stream
The stream to write data to.
The stream to write data to .
remarks
Use the  property to determine whether the stream instance supports writing.
Use the property to determine whether the stream instance supports writing .