using System.IO.Compression;
using System.Threading.Tasks;
public static void Main()
var sampleData = new byte[ 35000 ];
Console.WriteLine( "With GZipStream, WriteAsync NOT called" );
using( var fs = new MemoryStream( sampleData ) )
using (var ss = new GZipStream(new SampleStream(), CompressionMode.Compress))
await fs.CopyToAsync(ss);
Console.WriteLine( "Without GZipStream, WriteAsync *correctly* called" );
using( var fs = new MemoryStream( sampleData ) )
using (var ss = new SampleStream())
await fs.CopyToAsync(ss);
Console.WriteLine( "Complete" );
Console.WriteLine( ex.Message );
public class SampleStream : System.IO.Stream
public override bool CanRead { get { return true; } }
public override bool CanSeek { get { return false; } }
public override bool CanWrite { get { return true; } }
public override long Seek(long offset, SeekOrigin origin)
throw new NotImplementedException();
public override long Length
get { throw new NotImplementedException(); }
public override void SetLength(long value)
throw new NotImplementedException();
public override long Position
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
public override void Flush() { Console.WriteLine( "Flush" ); }
public override int Read(byte[] buffer, int offset, int count)
Console.WriteLine( "Read" );
public override void Write(byte[] buffer, int offset, int count) { Console.WriteLine( "Write" ); }
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
if (!cancellationToken.IsCancellationRequested)
Console.WriteLine("ReadAsync");
return Task.FromResult( 0 );
return Task.FromResult( 0 );
public async override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Console.WriteLine("WriteAsync");