lib/Task-Parallel-Library/StreamExtensions.cs
/// <summary>
/// Asynchronously reads a sequence of bytes from a stream and advances the position within the stream by the number of bytes read.
/// </summary>
/// <remarks>
/// Use the <see cref="Stream.CanRead"/> property to determine whether the stream instance supports reading.
/// </remarks>
/// <param name="stream">The stream to read data from.</param>
/// <param name="buffer">The buffer to write the data into.</param>
/// <param name="offset">The byte offset in <paramref name="buffer"/> at which to begin writing data from the stream.</param>
/// <param name="count">The maximum number of bytes to read.</param>
/// <returns>
/// A task that represents the asynchronous read operation. When the task completes successfully, the <see cref="Task{TResult}.Result"/>
/// property contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if
/// the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the stream has been reached.
/// </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 reading.</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 read operation.</exception>
Asynchronously reads a sequence of bytes from a stream and advances the position within the stream by the number of bytes read.
Asynchronously reads a sequence of bytes from a stream and advances the position within the stream by the number of bytes read .
public static Task<int> ReadAsync(this Stream stream, byte[] buffer, int offset, int count)
        {
            #if NET45PLUS
            if (stream == null)
            throw new ArgumentNullException("stream");
            return stream.ReadAsync(buffer, offset, count);
            #else
            return ReadAsync(stream, buffer, offset, count, CancellationToken.None);
            #endif
        }
public static Task < int > ReadAsync ( this Stream stream , byte [ ] buffer , int offset , int count ) { if NET45PLUS if ( stream == null ) throw new ArgumentNullException ( " " ) ; return stream . ReadAsync ( buffer , offset , count ) ; else return ReadAsync ( stream , buffer , offset , count , CancellationToken . None ) ; endif }
Asynchronously reads a sequence of bytes from a stream and advances the position within the stream by the number of bytes read.
Asynchronously reads a sequence of bytes from a stream and advances the position within the stream by the number of bytes read .
// This code requires the `Stream` class provide an implementation of `FlushAsync`. The unit tests will // detect any case where this results in a stack overflow.
A task that represents the asynchronous read operation. When the task completes successfully, the
property contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if
the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the stream has been reached.
A task that represents the asynchronous read operation . When the task completes successfully the property contains the total number of bytes read into the buffer . The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number or it can be 0 ( zero ) if the end of the stream has been reached .
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 reading.
If does not support reading .
If  has been disposed.
If has been disposed .
If  is currently in use by a previous read operation.
If is currently in use by a previous read operation .
Stream
this
buffer
byte[]
The buffer to write the data into.
The buffer to write the data into .
offset
int
The byte offset in  at which to begin writing data from the stream.
The byte offset in at which to begin writing data from the stream .
count
int
The maximum number of bytes to read.
The maximum number of bytes to read .
stream
The stream to read data from.
The stream to read data from .
remarks
Use the  property to determine whether the stream instance supports reading.
Use the property to determine whether the stream instance supports reading .