ReadAsync() public method

public ReadAsync ( byte array, int offset, int count, System cancellationToken ) : System.Threading.Tasks.Task
array byte
offset int
count int
cancellationToken System
return System.Threading.Tasks.Task
Example #1
0
 public override Task <int> ReadAsync(Byte[] array, int offset, int count, CancellationToken cancellationToken)
 {
     CheckDeflateStream();
     return(_deflateStream.ReadAsync(array, offset, count, cancellationToken));
 }
Example #2
0
        // Making this async since regular read/write are tested below
        private static async Task DecompressAsync(MemoryStream compareStream, MemoryStream gzStream)
        {
            var strippedMs = StripHeaderAndFooter.Strip(gzStream);

            var ms = new MemoryStream();
            var zip = new DeflateStream(strippedMs, CompressionMode.Decompress);

            var deflateStream = new MemoryStream();

            int _bufferSize = 1024;
            var bytes = new Byte[_bufferSize];
            bool finished = false;
            int retCount;
            while (!finished)
            {
                retCount = await zip.ReadAsync(bytes, 0, _bufferSize);

                if (retCount != 0)
                    await deflateStream.WriteAsync(bytes, 0, retCount);
                else
                    finished = true;
            }

            deflateStream.Position = 0;
            compareStream.Position = 0;

            byte[] compareArray = compareStream.ToArray();
            byte[] writtenArray = deflateStream.ToArray();

            Assert.Equal(compareArray.Length, writtenArray.Length);
            for (int i = 0; i < compareArray.Length; i++)
            {
                Assert.Equal(compareArray[i], writtenArray[i]);
            }
        }