/// <inheritdoc /> public async Task <byte[]> ReadBytesAsync(int count) { byte[] bytes = new byte[count]; int readCount = await ManagedStream.ReadAsync(bytes, 0, count) .ConfigureAwait(false); if (readCount != count) { throw new InvalidOperationException($"Failed to read {count} bytes from the stream."); } return(bytes); }
/// <inheritdoc /> public async Task <byte> ReadByteAsync() { byte[] singleByteBuffer = new byte[1]; //would be -1 if it's invalid int readResult = await ManagedStream.ReadAsync(singleByteBuffer, 0, 1) .ConfigureAwait(false); if (readResult == 0) { throw new InvalidOperationException($"Failed to read byte in {nameof(ReadByteAsync)}."); } return(singleByteBuffer[0]); }