Example #1
0
        public async override Task <int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
        {
            try
            {
                int bytes = await UnderlyingStream.ReadAsync(buffer, offset, count);

                _Position += bytes;

                Logger?.LogDebug($"StreamRequestWrapper: Read(buffer, {offset}, {count}) returned {bytes} Position: {this.Position} Length: {this.Length}");

                return(bytes);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public override async Task <int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
        {
            try
            {
                var readCount = await UnderlyingStream.ReadAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false);

                _position += readCount;
                return(readCount);
            }
            catch (Exception exception)
            {
                if (!ErrorIsRecoverable(exception))
                {
                    throw new ResumableStreamException("Unrecoverable read error occured", exception);
                }

                OnRecoverableError(new StreamErrorEventArgs(OperationType.Read, Position, count, exception));
                await RecoverAsync(count, cancellationToken).ConfigureAwait(false);

                return(await ReadAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false));
            }
        }
Example #3
0
 ///<inheritdoc />
 public override Task <int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
 {
     ThrowIfDisposed();
     return(UnderlyingStream.ReadAsync(buffer, offset, count, cancellationToken));
 }