Exemplo n.º 1
0
 /// <summary>
 /// Method to read a fixed-size buffer from the <see cref="Stream"/>. The read must return all bytes
 /// in the buffer's length; or else the <see cref="IoResult.Result"/> is
 /// <see cref="IoResultState.BadData"/>. Note that this method catches all exceptions and will
 /// <see cref="IoResult.Fault"/> the result. The read operation updates the
 /// <see cref="IoResult.BytesReadOrWritten"/> property: if there is an incoming value, it is incremented.
 /// </summary>
 /// <param name="ioResult">Not null.</param>
 /// <param name="sourceStream">Not null.</param>
 /// <param name="fixedBuffer">Not null.</param>
 /// <returns>Completes when the read completes.</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static Task <IoResult> ReadAllAsync(this IoResult ioResult, Stream sourceStream, byte[] fixedBuffer)
 {
     if (ioResult == null)
     {
         throw new ArgumentNullException(nameof(ioResult));
     }
     return(IoHelper.ReadAllAsync(sourceStream, fixedBuffer, ioResult));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Method to read a fixed-size buffer from the <see cref="Stream"/>. The read must return all bytes
 /// in the buffer's length; or else the <see cref="IoResult.Result"/> is
 /// <see cref="IoResultState.BadData"/>. Note that this method catches all exceptions and will
 /// <see cref="IoResult.Fault"/> the result. The read operation updates the
 /// <see cref="IoResult.BytesReadOrWritten"/> property: if there is an incoming value, it is incremented.
 /// </summary>
 /// <param name="sourceStream">Not null.</param>
 /// <param name="fixedBuffer">Not null.</param>
 /// <param name="ioResult">Optional. If null, a new instance is created; with any given
 /// <see cref="CancellationToken"/>.</param>
 /// <param name="cancellationToken">Optional.</param>
 /// <returns>Not null. If you provided an argument, the same object is returned.</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static async Task <IoResult> ReadAllAsync(
     Stream sourceStream,
     byte[] fixedBuffer,
     IoResult ioResult = null,
     CancellationToken cancellationToken = default)
 => await IoHelper.ReadAllAsync(
     sourceStream,
     fixedBuffer,
     0,
     fixedBuffer.Length,
     ioResult,
     cancellationToken);
Exemplo n.º 3
0
 /// <summary>
 /// Method to read to a buffer from the <see cref="Stream"/>. The read must return all bytes in the
 /// given <c>length</c>; or else the <see cref="IoResult.Result"/> is
 /// <see cref="IoResultState.BadData"/>. Note that this method catches all exceptions and will
 /// <see cref="IoResult.Fault"/> the result. This method takes an <c>offset</c> and  <c>length</c> within
 /// the <c>buffer</c>; and updates the <see cref="IoResult.BytesReadOrWritten"/> property: notice that
 /// if there is an incoming value, it is incremented.
 /// </summary>
 /// <param name="ioResult">Not null.</param>
 /// <param name="sourceStream">Not null.</param>
 /// <param name="buffer">Not null.</param>
 /// <param name="offset">Offset within <c>buffer</c> to begin reading.</param>
 /// <param name="length">Length within <c>buffer</c> to read.</param>
 /// <returns>Completes when the read completes.</returns>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="ArgumentOutOfRangeException"></exception>
 public static Task <IoResult> ReadAllAsync(
     this IoResult ioResult,
     Stream sourceStream,
     byte[] buffer,
     int offset,
     int length)
 {
     if (ioResult == null)
     {
         throw new ArgumentNullException(nameof(ioResult));
     }
     return(IoHelper.ReadAllAsync(sourceStream, buffer, offset, length, ioResult));
 }