Permalink
Browse files

Merge pull request #31013 from sharwell/rm-method

Remove unused method SerializableBytes.CreateReadableStream
  • Loading branch information...
sharwell committed Nov 9, 2018
2 parents 5ba6a80 + f471886 commit 4b91db6c5524c38293bd4cb809d4ac9ba3e4c71b
@@ -28,50 +28,6 @@ internal static PooledStream CreateReadableStream(byte[] bytes, int length)
return stream;
}
internal static PooledStream CreateReadableStream(Stream stream, CancellationToken cancellationToken)
{
long length = stream.Length;
long chunkCount = (length + ChunkSize - 1) / ChunkSize;
byte[][] chunks = new byte[chunkCount][];
try
{
for (long i = 0, c = 0; i < length; i += ChunkSize, c++)
{
int count = (int)Math.Min(ChunkSize, length - i);
var chunk = SharedPools.ByteArray.Allocate();
int chunkOffset = 0;
while (count > 0)
{
cancellationToken.ThrowIfCancellationRequested();
int bytesRead = stream.Read(chunk, chunkOffset, count);
if (bytesRead > 0)
{
count = count - bytesRead;
chunkOffset += bytesRead;
}
else
{
break;
}
}
chunks[c] = chunk;
}
var result = new ReadStream(length, chunks);
chunks = null;
return result;
}
finally
{
BlowChunks(chunks);
}
}
internal async static Task<PooledStream> CreateReadableStreamAsync(Stream stream, CancellationToken cancellationToken)
{
long length = stream.Length;
@@ -3,15 +3,15 @@
using System;
using System.IO;
using System.Threading;
using Roslyn.Utilities;
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.CodeAnalysis.UnitTests
{
public class SerializableBytesTests
{
[Fact]
public void ReadableStreamTestReadAByteAtATime()
public async Task ReadableStreamTestReadAByteAtATime()
{
using (var expected = new MemoryStream())
{
@@ -21,7 +21,7 @@ public void ReadableStreamTestReadAByteAtATime()
}
expected.Position = 0;
using (var stream = SerializableBytes.CreateReadableStream(expected, CancellationToken.None))
using (var stream = await SerializableBytes.CreateReadableStreamAsync(expected, CancellationToken.None))
{
Assert.Equal(expected.Length, stream.Length);
@@ -36,7 +36,7 @@ public void ReadableStreamTestReadAByteAtATime()
}
[Fact]
public void ReadableStreamTestReadChunks()
public async Task ReadableStreamTestReadChunks()
{
using (var expected = new MemoryStream())
{
@@ -46,7 +46,7 @@ public void ReadableStreamTestReadChunks()
}
expected.Position = 0;
using (var stream = SerializableBytes.CreateReadableStream(expected, CancellationToken.None))
using (var stream = await SerializableBytes.CreateReadableStreamAsync(expected, CancellationToken.None))
{
Assert.Equal(expected.Length, stream.Length);
@@ -71,7 +71,7 @@ public void ReadableStreamTestReadChunks()
}
[Fact]
public void ReadableStreamTestReadRandomBytes()
public async Task ReadableStreamTestReadRandomBytes()
{
using (var expected = new MemoryStream())
{
@@ -81,7 +81,7 @@ public void ReadableStreamTestReadRandomBytes()
}
expected.Position = 0;
using (var stream = SerializableBytes.CreateReadableStream(expected, CancellationToken.None))
using (var stream = await SerializableBytes.CreateReadableStreamAsync(expected, CancellationToken.None))
{
Assert.Equal(expected.Length, stream.Length);

0 comments on commit 4b91db6

Please sign in to comment.