Skip to content

Commit

Permalink
cr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Feb 11, 2016
1 parent 3f9f85a commit d3aff53
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public FileBufferingReadStream(

// TODO: allow for an optional buffer size limit to prevent filling hard disks. 1gb?
public FileBufferingReadStream(Stream inner, int memoryThreshold, string tempFileDirectory)
: this (inner, memoryThreshold, tempFileDirectory, ArrayPool<byte>.Shared)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ public override int Read(byte[] buffer, int offset, int count)
// or -- for the final boundary.
var boundary = _bytePool.Rent(_boundaryBytes.Length);
read = _innerStream.Read(boundary, 0, _boundaryBytes.Length);
_bytePool.Return(boundary);
Debug.Assert(read == _boundaryBytes.Length); // It should have all been buffered
var remainder = _innerStream.ReadLine(lengthLimit: 100); // Whitespace may exceed the buffer.
remainder = remainder.Trim();
if (string.Equals("--", remainder, StringComparison.Ordinal))
{
FinalBoundaryFound = true;
}
_bytePool.Return(boundary);
Debug.Assert(FinalBoundaryFound || string.Equals(string.Empty, remainder, StringComparison.Ordinal), "Un-expected data found on the boundary line: " + remainder);
_finished = true;
return 0;
Expand Down Expand Up @@ -294,14 +294,14 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
// or -- for the final boundary.
var boundary = _bytePool.Rent(_boundaryBytes.Length);
read = _innerStream.Read(boundary, 0, _boundaryBytes.Length);
_bytePool.Return(boundary);
Debug.Assert(read == _boundaryBytes.Length); // It should have all been buffered
var remainder = await _innerStream.ReadLineAsync(lengthLimit: 100, cancellationToken: cancellationToken); // Whitespace may exceed the buffer.
remainder = remainder.Trim();
if (string.Equals("--", remainder, StringComparison.Ordinal))
{
FinalBoundaryFound = true;
}
_bytePool.Return(boundary);
Debug.Assert(FinalBoundaryFound || string.Equals(string.Empty, remainder, StringComparison.Ordinal), "Un-expected data found on the boundary line: " + remainder);

_finished = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public static class StreamHelperExtensions
{
public static Task DrainAsync(this Stream stream, CancellationToken cancellationToken)
{
return stream.DrainAsync(cancellationToken, ArrayPool<byte>.Shared);
return stream.DrainAsync(ArrayPool<byte>.Shared, cancellationToken);
}
public static async Task DrainAsync(this Stream stream, CancellationToken cancellationToken, ArrayPool<byte> bytePool)
public static async Task DrainAsync(this Stream stream, ArrayPool<byte> bytePool, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var buffer = bytePool.Rent(1024);
Expand Down

0 comments on commit d3aff53

Please sign in to comment.