diff --git a/src/Microsoft.AspNetCore.WebUtilities/BufferedReadStream.cs b/src/Microsoft.AspNetCore.WebUtilities/BufferedReadStream.cs
index b72920df4d..10f1465f3a 100644
--- a/src/Microsoft.AspNetCore.WebUtilities/BufferedReadStream.cs
+++ b/src/Microsoft.AspNetCore.WebUtilities/BufferedReadStream.cs
@@ -10,7 +10,11 @@ using System.Threading.Tasks;
namespace Microsoft.AspNetCore.WebUtilities
{
- internal class BufferedReadStream : Stream
+ ///
+ /// A Stream that wraps another stream and allows reading lines.
+ /// The data is buffered in memory.
+ ///
+ public class BufferedReadStream : Stream
{
private const byte CR = (byte)'\r';
private const byte LF = (byte)'\n';
@@ -22,11 +26,22 @@ namespace Microsoft.AspNetCore.WebUtilities
private int _bufferCount = 0;
private bool _disposed;
+ ///
+ /// Creates a new stream.
+ ///
+ /// The stream to wrap.
+ /// Size of buffer in bytes.
public BufferedReadStream(Stream inner, int bufferSize)
: this(inner, bufferSize, ArrayPool.Shared)
{
}
+ ///
+ /// Creates a new stream.
+ ///
+ /// The stream to wrap.
+ /// Size of buffer in bytes.
+ /// ArrayPool for the buffer.
public BufferedReadStream(Stream inner, int bufferSize, ArrayPool bytePool)
{
if (inner == null)
@@ -39,36 +54,45 @@ namespace Microsoft.AspNetCore.WebUtilities
_buffer = bytePool.Rent(bufferSize);
}
+ ///
+ /// The currently buffered data.
+ ///
public ArraySegment BufferedData
{
get { return new ArraySegment(_buffer, _bufferOffset, _bufferCount); }
}
+ ///
public override bool CanRead
{
get { return _inner.CanRead || _bufferCount > 0; }
}
+ ///
public override bool CanSeek
{
get { return _inner.CanSeek; }
}
+ ///
public override bool CanTimeout
{
get { return _inner.CanTimeout; }
}
+ ///
public override bool CanWrite
{
get { return _inner.CanWrite; }
}
+ ///
public override long Length
{
get { return _inner.Length; }
}
+ ///
public override long Position
{
get { return _inner.Position - _bufferCount; }
@@ -112,6 +136,7 @@ namespace Microsoft.AspNetCore.WebUtilities
}
}
+ ///
public override long Seek(long offset, SeekOrigin origin)
{
if (origin == SeekOrigin.Begin)
@@ -129,11 +154,13 @@ namespace Microsoft.AspNetCore.WebUtilities
return Position;
}
+ ///
public override void SetLength(long value)
{
_inner.SetLength(value);
}
+ ///
protected override void Dispose(bool disposing)
{
if (!_disposed)
@@ -148,26 +175,31 @@ namespace Microsoft.AspNetCore.WebUtilities
}
}
+ ///
public override void Flush()
{
_inner.Flush();
}
+ ///
public override Task FlushAsync(CancellationToken cancellationToken)
{
return _inner.FlushAsync(cancellationToken);
}
+ ///
public override void Write(byte[] buffer, int offset, int count)
{
_inner.Write(buffer, offset, count);
}
+ ///
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return _inner.WriteAsync(buffer, offset, count, cancellationToken);
}
+ ///
public override int Read(byte[] buffer, int offset, int count)
{
ValidateBuffer(buffer, offset, count);
@@ -185,6 +217,7 @@ namespace Microsoft.AspNetCore.WebUtilities
return _inner.Read(buffer, offset, count);
}
+ ///
public async override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
ValidateBuffer(buffer, offset, count);
@@ -202,6 +235,10 @@ namespace Microsoft.AspNetCore.WebUtilities
return await _inner.ReadAsync(buffer, offset, count, cancellationToken);
}
+ ///
+ /// Ensures that the buffer is not empty.
+ ///
+ /// Returns true if the buffer is not empty; false otherwise.
public bool EnsureBuffered()
{
if (_bufferCount > 0)
@@ -214,6 +251,11 @@ namespace Microsoft.AspNetCore.WebUtilities
return _bufferCount > 0;
}
+ ///
+ /// Ensures that the buffer is not empty.
+ ///
+ /// Cancellation token.
+ /// Returns true if the buffer is not empty; false otherwise.
public async Task EnsureBufferedAsync(CancellationToken cancellationToken)
{
if (_bufferCount > 0)
@@ -226,6 +268,11 @@ namespace Microsoft.AspNetCore.WebUtilities
return _bufferCount > 0;
}
+ ///
+ /// Ensures that a minimum amount of buffered data is available.
+ ///
+ /// Minimum amount of buffered data.
+ /// Returns true if the minimum amount of buffered data is available; false otherwise.
public bool EnsureBuffered(int minCount)
{
if (minCount > _buffer.Length)
@@ -253,6 +300,12 @@ namespace Microsoft.AspNetCore.WebUtilities
return true;
}
+ ///
+ /// Ensures that a minimum amount of buffered data is available.
+ ///
+ /// Minimum amount of buffered data.
+ /// Cancellation token.
+ /// Returns true if the minimum amount of buffered data is available; false otherwise.
public async Task EnsureBufferedAsync(int minCount, CancellationToken cancellationToken)
{
if (minCount > _buffer.Length)
@@ -280,6 +333,13 @@ namespace Microsoft.AspNetCore.WebUtilities
return true;
}
+ ///
+ /// Reads a line. A line is defined as a sequence of characters followed by
+ /// a carriage return immediately followed by a line feed. The resulting string does not
+ /// contain the terminating carriage return and line feed.
+ ///
+ /// Maximum allowed line length.
+ /// A line.
public string ReadLine(int lengthLimit)
{
CheckDisposed();
@@ -300,6 +360,14 @@ namespace Microsoft.AspNetCore.WebUtilities
}
}
+ ///
+ /// Reads a line. A line is defined as a sequence of characters followed by
+ /// a carriage return immediately followed by a line feed. The resulting string does not
+ /// contain the terminating carriage return and line feed.
+ ///
+ /// Maximum allowed line length.
+ /// Cancellation token.
+ /// A line.
public async Task ReadLineAsync(int lengthLimit, CancellationToken cancellationToken)
{
CheckDisposed();