public void Precancellation() { var ms = new MemoryStream(); using (Stream compressor = new DeflateStream(ms, CompressionMode.Compress, leaveOpen: true)) { Assert.True(compressor.WriteAsync(new byte[1], 0, 1, new CancellationToken(true)).IsCanceled); Assert.True(compressor.FlushAsync(new CancellationToken(true)).IsCanceled); } using (Stream decompressor = CreateStream(ms, CompressionMode.Decompress, leaveOpen: true)) { Assert.True(decompressor.ReadAsync(new byte[1], 0, 1, new CancellationToken(true)).IsCanceled); } }
public static async Task FlushAsyncFailsAfterDispose() { var ms = new MemoryStream(); var ds = new DeflateStream(ms, CompressionMode.Compress); ds.Dispose(); await Assert.ThrowsAsync<ObjectDisposedException>(async () => { await ds.FlushAsync(); }); }
public override Task FlushAsync(CancellationToken cancellationToken) { CheckDeflateStream(); return(_deflateStream.FlushAsync(cancellationToken)); }
public static async Task Flush() { var ms = new MemoryStream(); var ds = new DeflateStream(ms, CompressionMode.Compress); ds.Flush(); await ds.FlushAsync(); // Just ensuring Flush doesn't throw }