< Summary

Information
Class: System.IO.Compression.DeflateStream
Assembly: System.IO.Compression
File(s): D:\runner\runtime\src\libraries\System.IO.Compression\src\System\IO\Compression\DeflateZLib\DeflateStream.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 679
Coverable lines: 679
Total lines: 1149
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 259
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
.ctor(...)100%110%
.ctor(...)100%110%
.ctor(...)100%110%
.ctor(...)100%110%
.ctor(...)100%110%
.ctor(...)100%110%
.ctor(...)0%660%
.ctor(...)100%110%
InitializeDeflater(...)0%220%
GetZLibNativeCompressionLevel(...)0%550%
GetMemLevel(...)0%220%
InitializeBuffer()100%110%
EnsureBufferInitialized()0%220%
Flush()0%220%
FlushAsync(...)0%440%
Core(System.Threading.CancellationToken)0%660%
Seek(...)100%110%
SetLength(...)100%110%
ReadByte()0%220%
Read(...)100%110%
Read(...)0%220%
ReadCore(...)0%28280%
EnsureNotDisposed()100%110%
EnsureDecompressionMode()0%220%
ThrowCannotReadFromDeflateStreamException()100%110%
EnsureCompressionMode()0%220%
ThrowCannotWriteToDeflateStreamException()100%110%
ThrowGenericInvalidData()100%110%
ThrowTruncatedInvalidData()100%110%
BeginRead(...)100%110%
EndRead(...)100%110%
ReadAsync(...)100%110%
ReadAsync(...)0%220%
ReadAsyncMemory(...)0%220%
Core(System.Memory`1<System.Byte>,System.Threading.CancellationToken)0%28280%
Write(...)100%110%
WriteByte(...)0%220%
Write(...)0%220%
WriteCore(...)0%220%
WriteDeflaterOutput()0%660%
FlushBuffers()0%660%
PurgeBuffers(...)0%12120%
PurgeBuffersAsync()0%10100%
TryRewindStream(...)0%220%
Dispose(...)0%14140%
DisposeAsync()0%220%
Core()0%16160%
BeginWrite(...)100%110%
EndWrite(...)100%110%
WriteAsync(...)100%110%
WriteAsync(...)0%220%
WriteAsyncMemory(...)0%440%
Core(System.ReadOnlyMemory`1<System.Byte>,System.Threading.CancellationToken)100%110%
WriteDeflaterOutputAsync(...)0%660%
CopyTo(...)0%220%
CopyToAsync(...)0%440%
.ctor(...)100%110%
.ctor(...)100%110%
CopyFromSourceToDestinationAsync()0%16160%
CopyFromSourceToDestination()0%16160%
WriteAsync(...)0%440%
WriteAsync(...)100%110%
WriteAsyncCore(...)0%660%
Write(...)0%10100%
Flush()100%110%
Read(...)100%110%
Seek(...)100%110%
SetLength(...)100%110%
EnsureNoActiveAsyncOperation()0%220%
AsyncOperationStarting()0%220%
AsyncOperationCompleting()100%110%
ThrowInvalidBeginCall()100%110%
.cctor()0%220%

File(s)

D:\runner\runtime\src\libraries\System.IO.Compression\src\System\IO\Compression\DeflateZLib\DeflateStream.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Buffers;
 5using System.Diagnostics;
 6using System.Diagnostics.CodeAnalysis;
 7using System.Runtime.InteropServices;
 8using System.Threading;
 9using System.Threading.Tasks;
 10using static System.IO.Compression.ZLibNative;
 11
 12namespace System.IO.Compression
 13{
 14    public partial class DeflateStream : Stream
 15    {
 16        private const int DefaultBufferSize = 8192;
 17
 18        private Stream _stream;
 19        private CompressionMode _mode;
 20        private bool _leaveOpen;
 21        private Inflater? _inflater;
 22        private Deflater? _deflater;
 23        private byte[]? _buffer;
 24        private volatile bool _activeAsyncOperation;
 25        private volatile bool _decompressionFinished;
 26
 027        internal DeflateStream(Stream stream, CompressionMode mode, long uncompressedSize) : this(stream, mode, leaveOpe
 028        {
 029        }
 30
 031        public DeflateStream(Stream stream, CompressionMode mode) : this(stream, mode, leaveOpen: false)
 032        {
 033        }
 34
 035        public DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen) : this(stream, mode, leaveOpen, ZLibNa
 036        {
 037        }
 38
 39        // Implies mode = Compress
 040        public DeflateStream(Stream stream, CompressionLevel compressionLevel) : this(stream, compressionLevel, leaveOpe
 041        {
 042        }
 43
 44        // Implies mode = Compress
 045        public DeflateStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen) : this(stream, compressio
 046        {
 047        }
 48
 49        /// <summary>
 50        /// Initializes a new instance of the <see cref="DeflateStream"/> class by using the specified stream, compressi
 51        /// </summary>
 52        /// <param name="stream">The stream to which compressed data is written.</param>
 53        /// <param name="compressionOptions">The options for fine tuning the compression stream.</param>
 54        /// <param name="leaveOpen"><see langword="true" /> to leave the stream object open after disposing the <see cre
 55        /// <exception cref="ArgumentNullException"><paramref name="stream"/> or <paramref name="compressionOptions"/> i
 056        public DeflateStream(Stream stream, ZLibCompressionOptions compressionOptions, bool leaveOpen = false)
 057        {
 058            ArgumentNullException.ThrowIfNull(stream);
 059            ArgumentNullException.ThrowIfNull(compressionOptions);
 60
 061            int windowBits = CompressionFormatHelper.ResolveWindowBits(compressionOptions.WindowLog2, CompressionFormat.
 62
 063            InitializeDeflater(stream, (ZLibNative.CompressionLevel)compressionOptions.CompressionLevel, (CompressionStr
 064        }
 65
 066        internal DeflateStream(Stream stream, ZLibCompressionOptions compressionOptions, bool leaveOpen, int windowBits)
 067        {
 068            ArgumentNullException.ThrowIfNull(stream);
 069            ArgumentNullException.ThrowIfNull(compressionOptions);
 70
 071            InitializeDeflater(stream, (ZLibNative.CompressionLevel)compressionOptions.CompressionLevel, (CompressionStr
 072        }
 73
 74        /// <summary>
 75        /// Internal constructor to check stream validity and call the correct initialization function depending on
 76        /// the value of the CompressionMode given.
 77        /// </summary>
 078        internal DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen, int windowBits, long uncompressedSiz
 079        {
 080            ArgumentNullException.ThrowIfNull(stream);
 81
 082            switch (mode)
 83            {
 84                case CompressionMode.Decompress:
 085                    if (!stream.CanRead)
 086                        throw new ArgumentException(SR.NotSupported_UnreadableStream, nameof(stream));
 87
 088                    _inflater = Inflater.CreateInflater(windowBits, uncompressedSize);
 089                    _stream = stream;
 090                    _mode = CompressionMode.Decompress;
 091                    _leaveOpen = leaveOpen;
 092                    break;
 93
 94                case CompressionMode.Compress:
 095                    InitializeDeflater(stream, ZLibNative.CompressionLevel.DefaultCompression, CompressionStrategy.Defau
 096                    break;
 97
 98                default:
 099                    throw new ArgumentException(SR.ArgumentOutOfRange_Enum, nameof(mode));
 100            }
 0101        }
 102
 103        /// <summary>
 104        /// Internal constructor to specify the compressionLevel as well as the windowBits
 105        /// </summary>
 0106        internal DeflateStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen, int windowBits)
 0107        {
 0108            ArgumentNullException.ThrowIfNull(stream);
 109
 0110            InitializeDeflater(stream, GetZLibNativeCompressionLevel(compressionLevel), CompressionStrategy.DefaultStrat
 0111        }
 112
 113        /// <summary>
 114        /// Sets up this DeflateStream to be used for Zlib Deflation/Compression
 115        /// </summary>
 116        [MemberNotNull(nameof(_stream))]
 117        internal void InitializeDeflater(Stream stream, ZLibNative.CompressionLevel compressionLevel, CompressionStrateg
 0118        {
 0119            Debug.Assert(stream != null);
 0120            if (!stream.CanWrite)
 0121                throw new ArgumentException(SR.NotSupported_UnwritableStream, nameof(stream));
 122
 0123            _deflater = Deflater.CreateDeflater(compressionLevel, strategy, windowBits, GetMemLevel(compressionLevel));
 124
 0125            _stream = stream;
 0126            _mode = CompressionMode.Compress;
 0127            _leaveOpen = leaveOpen;
 0128            InitializeBuffer();
 0129        }
 130
 131        private static ZLibNative.CompressionLevel GetZLibNativeCompressionLevel(CompressionLevel compressionLevel) =>
 0132            compressionLevel switch
 0133            {
 0134                CompressionLevel.Optimal => ZLibNative.CompressionLevel.DefaultCompression,
 0135                CompressionLevel.Fastest => ZLibNative.CompressionLevel.BestSpeed,
 0136                CompressionLevel.NoCompression => ZLibNative.CompressionLevel.NoCompression,
 0137                CompressionLevel.SmallestSize => ZLibNative.CompressionLevel.BestCompression,
 0138                _ => throw new ArgumentOutOfRangeException(nameof(compressionLevel)),
 0139            };
 140
 141        private static int GetMemLevel(ZLibNative.CompressionLevel level) =>
 0142            level == ZLibNative.CompressionLevel.NoCompression ?
 0143                Deflate_NoCompressionMemLevel :
 0144                Deflate_DefaultMemLevel;
 145
 146        [MemberNotNull(nameof(_buffer))]
 147        private void InitializeBuffer()
 0148        {
 0149            Debug.Assert(_buffer == null);
 0150            _buffer = ArrayPool<byte>.Shared.Rent(DefaultBufferSize);
 0151        }
 152
 153        [MemberNotNull(nameof(_buffer))]
 154        private void EnsureBufferInitialized()
 0155        {
 0156            if (_buffer == null)
 0157            {
 0158                InitializeBuffer();
 0159            }
 0160        }
 161
 162        public Stream BaseStream
 163        {
 164            get
 0165            {
 0166                EnsureNotDisposed();
 0167                return _stream;
 0168            }
 169        }
 170
 171        public override bool CanRead
 172        {
 173            get
 0174            {
 0175                if (_stream == null)
 0176                {
 0177                    return false;
 178                }
 179
 0180                return (_mode == CompressionMode.Decompress && _stream.CanRead);
 0181            }
 182        }
 183
 184        public override bool CanWrite
 185        {
 186            get
 0187            {
 0188                if (_stream == null)
 0189                {
 0190                    return false;
 191                }
 192
 0193                return (_mode == CompressionMode.Compress && _stream.CanWrite);
 0194            }
 195        }
 196
 0197        public override bool CanSeek => false;
 198
 199        public override long Length
 200        {
 0201            get { throw new NotSupportedException(SR.NotSupported); }
 202        }
 203
 204        public override long Position
 205        {
 0206            get { throw new NotSupportedException(SR.NotSupported); }
 0207            set { throw new NotSupportedException(SR.NotSupported); }
 208        }
 209
 210        public override void Flush()
 0211        {
 0212            EnsureNotDisposed();
 0213            if (_mode == CompressionMode.Compress)
 0214                FlushBuffers();
 0215        }
 216
 217        public override Task FlushAsync(CancellationToken cancellationToken)
 0218        {
 0219            EnsureNoActiveAsyncOperation();
 0220            EnsureNotDisposed();
 221
 0222            if (cancellationToken.IsCancellationRequested)
 0223                return Task.FromCanceled(cancellationToken);
 224
 0225            return _mode != CompressionMode.Compress ?
 0226                Task.CompletedTask :
 0227                Core(cancellationToken);
 228
 229            async Task Core(CancellationToken cancellationToken)
 0230            {
 0231                AsyncOperationStarting();
 232                try
 0233                {
 0234                    Debug.Assert(_deflater != null && _buffer != null);
 235
 236                    // Compress any bytes left:
 0237                    await WriteDeflaterOutputAsync(cancellationToken).ConfigureAwait(false);
 238
 239                    // Pull out any bytes left inside deflater:
 240                    bool flushSuccessful;
 241                    do
 0242                    {
 243                        int compressedBytes;
 0244                        flushSuccessful = _deflater.Flush(_buffer, out compressedBytes);
 0245                        if (flushSuccessful)
 0246                        {
 0247                            await _stream.WriteAsync(new ReadOnlyMemory<byte>(_buffer, 0, compressedBytes), cancellation
 0248                        }
 0249                        Debug.Assert(flushSuccessful == (compressedBytes > 0));
 0250                    } while (flushSuccessful);
 251
 252                    // Always flush on the underlying stream
 0253                    await _stream.FlushAsync(cancellationToken).ConfigureAwait(false);
 0254                }
 255                finally
 0256                {
 0257                    AsyncOperationCompleting();
 0258                }
 0259            }
 0260        }
 261
 262        public override long Seek(long offset, SeekOrigin origin)
 0263        {
 0264            throw new NotSupportedException(SR.NotSupported);
 265        }
 266
 267        public override void SetLength(long value)
 0268        {
 0269            throw new NotSupportedException(SR.NotSupported);
 270        }
 271
 272        public override int ReadByte()
 0273        {
 0274            EnsureDecompressionMode();
 0275            EnsureNotDisposed();
 276
 277            // Try to read a single byte from zlib without allocating an array, pinning an array, etc.
 278            // If zlib doesn't have any data, fall back to the base stream implementation, which will do that.
 279            byte b;
 0280            Debug.Assert(_inflater != null);
 0281            return _inflater.Inflate(out b) ? b : base.ReadByte();
 0282        }
 283
 284        public override int Read(byte[] buffer, int offset, int count)
 0285        {
 0286            ValidateBufferArguments(buffer, offset, count);
 0287            return ReadCore(new Span<byte>(buffer, offset, count));
 0288        }
 289
 290        public override int Read(Span<byte> buffer)
 0291        {
 0292            if (GetType() != typeof(DeflateStream))
 0293            {
 294                // DeflateStream is not sealed, and a derived type may have overridden Read(byte[], int, int) prior
 295                // to this Read(Span<byte>) overload being introduced.  In that case, this Read(Span<byte>) overload
 296                // should use the behavior of Read(byte[],int,int) overload.
 0297                return base.Read(buffer);
 298            }
 299            else
 0300            {
 0301                return ReadCore(buffer);
 302            }
 0303        }
 304
 305        internal int ReadCore(Span<byte> buffer)
 0306        {
 0307            EnsureDecompressionMode();
 0308            EnsureNotDisposed();
 0309            EnsureBufferInitialized();
 0310            Debug.Assert(_inflater != null);
 311
 312            int bytesRead;
 0313            while (true)
 0314            {
 315                // Try to decompress any data from the inflater into the caller's buffer.
 316                // If we're able to decompress any bytes, or if decompression is completed, we're done.
 0317                bytesRead = _inflater.Inflate(buffer);
 0318                if (bytesRead != 0 || InflatorIsFinished)
 0319                {
 0320                    break;
 321                }
 322
 323                // We were unable to decompress any data.  If the inflater needs additional input
 324                // data to proceed, read some to populate it.
 0325                if (_inflater.NeedsInput())
 0326                {
 0327                    int n = _stream.Read(_buffer, 0, _buffer.Length);
 0328                    if (n <= 0)
 0329                    {
 330                        // - Inflater didn't return any data although a non-empty output buffer was passed by the caller
 331                        // - More input is needed but there is no more input available.
 332                        // - Inflation is not finished yet.
 333                        // - Provided input wasn't completely empty
 334                        // In such case, we are dealing with a truncated input stream.
 0335                        if (s_useStrictValidation && !buffer.IsEmpty && !_inflater.Finished() && _inflater.NonEmptyInput
 0336                        {
 0337                            ThrowTruncatedInvalidData();
 0338                        }
 0339                        break;
 340                    }
 0341                    else if (n > _buffer.Length)
 0342                    {
 0343                        ThrowGenericInvalidData();
 0344                    }
 345                    else
 0346                    {
 0347                        _inflater.SetInput(_buffer, 0, n);
 0348                    }
 0349                }
 350
 0351                if (buffer.IsEmpty)
 0352                {
 353                    // The caller provided a zero-byte buffer.  This is typically done in order to avoid allocating/rent
 354                    // a buffer until data is known to be available.  We don't have perfect knowledge here, as _inflater
 355                    // will return 0 whether or not more data is required, and having input data doesn't necessarily mea
 356                    // decompress into at least one byte of output, but it's a reasonable approximation for the 99% case
 357                    // wrong, it just means that a caller using zero-byte reads as a way to delay getting a buffer to us
 358                    // subsequent call may end up getting one earlier than otherwise preferred.
 0359                    Debug.Assert(bytesRead == 0);
 0360                    break;
 361                }
 0362            }
 363
 364            // When decompression finishes, rewind the stream to the exact end of compressed data
 0365            if (bytesRead == 0 && InflatorIsFinished && !_decompressionFinished && _stream.CanSeek)
 0366            {
 0367                TryRewindStream(_stream);
 0368                _decompressionFinished = true;
 0369            }
 370
 0371            return bytesRead;
 0372        }
 373
 374        private bool InflatorIsFinished =>
 375            // If the stream is finished then we have a few potential cases here:
 376            // 1. DeflateStream => return
 377            // 2. GZipStream that is finished but may have an additional GZipStream appended => feed more input
 378            // 3. GZipStream that is finished and appended with garbage => return
 0379            _inflater!.Finished() &&
 0380            (!_inflater.IsGzipStream() || !_inflater.NeedsInput());
 381
 382        private void EnsureNotDisposed()
 0383        {
 0384            ObjectDisposedException.ThrowIf(_stream is null, this);
 0385        }
 386
 387        private void EnsureDecompressionMode()
 0388        {
 0389            if (_mode != CompressionMode.Decompress)
 0390                ThrowCannotReadFromDeflateStreamException();
 391
 392            static void ThrowCannotReadFromDeflateStreamException() =>
 0393                throw new InvalidOperationException(SR.CannotReadFromDeflateStream);
 0394        }
 395
 396        private void EnsureCompressionMode()
 0397        {
 0398            if (_mode != CompressionMode.Compress)
 0399                ThrowCannotWriteToDeflateStreamException();
 400
 401            static void ThrowCannotWriteToDeflateStreamException() =>
 0402                throw new InvalidOperationException(SR.CannotWriteToDeflateStream);
 0403        }
 404
 405        private static void ThrowGenericInvalidData() =>
 406            // The stream is either malicious or poorly implemented and returned a number of
 407            // bytes < 0 || > than the buffer supplied to it.
 0408            throw new InvalidDataException(SR.GenericInvalidData);
 409
 410        private static void ThrowTruncatedInvalidData() =>
 0411            throw new InvalidDataException(SR.TruncatedData);
 412
 413        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, objec
 0414            TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState)
 415
 416        public override int EndRead(IAsyncResult asyncResult)
 0417        {
 0418            EnsureDecompressionMode();
 0419            EnsureNotDisposed();
 0420            return TaskToAsyncResult.End<int>(asyncResult);
 0421        }
 422
 423        public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
 0424        {
 0425            ValidateBufferArguments(buffer, offset, count);
 0426            return ReadAsyncMemory(new Memory<byte>(buffer, offset, count), cancellationToken).AsTask();
 0427        }
 428
 429        public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
 0430        {
 0431            if (GetType() != typeof(DeflateStream))
 0432            {
 433                // Ensure that existing streams derived from DeflateStream and that override ReadAsync(byte[],...)
 434                // get their existing behaviors when the newer Memory-based overload is used.
 0435                return base.ReadAsync(buffer, cancellationToken);
 436            }
 437            else
 0438            {
 0439                return ReadAsyncMemory(buffer, cancellationToken);
 440            }
 0441        }
 442
 443        internal ValueTask<int> ReadAsyncMemory(Memory<byte> buffer, CancellationToken cancellationToken)
 0444        {
 0445            EnsureDecompressionMode();
 0446            EnsureNoActiveAsyncOperation();
 0447            EnsureNotDisposed();
 448
 0449            if (cancellationToken.IsCancellationRequested)
 0450            {
 0451                return ValueTask.FromCanceled<int>(cancellationToken);
 452            }
 453
 0454            EnsureBufferInitialized();
 0455            Debug.Assert(_inflater != null);
 456
 0457            return Core(buffer, cancellationToken);
 458
 459            async ValueTask<int> Core(Memory<byte> buffer, CancellationToken cancellationToken)
 0460            {
 0461                AsyncOperationStarting();
 462                try
 0463                {
 464                    int bytesRead;
 0465                    while (true)
 0466                    {
 467                        // Try to decompress any data from the inflater into the caller's buffer.
 468                        // If we're able to decompress any bytes, or if decompression is completed, we're done.
 0469                        bytesRead = _inflater.Inflate(buffer.Span);
 0470                        if (bytesRead != 0 || InflatorIsFinished)
 0471                        {
 0472                            break;
 473                        }
 474
 475                        // We were unable to decompress any data.  If the inflater needs additional input
 476                        // data to proceed, read some to populate it.
 0477                        if (_inflater.NeedsInput())
 0478                        {
 0479                            int n = await _stream.ReadAsync(new Memory<byte>(_buffer, 0, _buffer.Length), cancellationTo
 0480                            if (n <= 0)
 0481                            {
 482                                // - Inflater didn't return any data although a non-empty output buffer was passed by th
 483                                // - More input is needed but there is no more input available.
 484                                // - Inflation is not finished yet.
 485                                // - Provided input wasn't completely empty
 486                                // In such case, we are dealing with a truncated input stream.
 0487                                if (s_useStrictValidation && !_inflater.Finished() && _inflater.NonEmptyInput() && !buff
 0488                                {
 0489                                    ThrowTruncatedInvalidData();
 0490                                }
 0491                                break;
 492                            }
 0493                            else if (n > _buffer.Length)
 0494                            {
 0495                                ThrowGenericInvalidData();
 0496                            }
 497                            else
 0498                            {
 0499                                _inflater.SetInput(_buffer, 0, n);
 0500                            }
 0501                        }
 502
 0503                        if (buffer.IsEmpty)
 0504                        {
 505                            // The caller provided a zero-byte buffer.  This is typically done in order to avoid allocat
 506                            // a buffer until data is known to be available.  We don't have perfect knowledge here, as _
 507                            // will return 0 whether or not more data is required, and having input data doesn't necessa
 508                            // decompress into at least one byte of output, but it's a reasonable approximation for the 
 509                            // wrong, it just means that a caller using zero-byte reads as a way to delay getting a buff
 510                            // subsequent call may end up getting one earlier than otherwise preferred.
 0511                            break;
 512                        }
 0513                    }
 514
 515                    // When decompression finishes, rewind the stream to the exact end of compressed data
 0516                    if (bytesRead == 0 && InflatorIsFinished && !_decompressionFinished && _stream.CanSeek)
 0517                    {
 0518                        TryRewindStream(_stream);
 0519                        _decompressionFinished = true;
 0520                    }
 521
 0522                    return bytesRead;
 523                }
 524                finally
 0525                {
 0526                    AsyncOperationCompleting();
 0527                }
 0528            }
 0529        }
 530
 531        public override void Write(byte[] buffer, int offset, int count)
 0532        {
 0533            ValidateBufferArguments(buffer, offset, count);
 0534            WriteCore(new ReadOnlySpan<byte>(buffer, offset, count));
 0535        }
 536
 537        public override void WriteByte(byte value)
 0538        {
 0539            if (GetType() != typeof(DeflateStream))
 0540            {
 541                // DeflateStream is not sealed, and a derived type may have overridden Write(byte[], int, int) prior
 542                // to this WriteByte override being introduced.  In that case, this WriteByte override
 543                // should use the behavior of the Write(byte[],int,int) overload.
 0544                base.WriteByte(value);
 0545            }
 546            else
 0547            {
 0548                WriteCore(new ReadOnlySpan<byte>(in value));
 0549            }
 0550        }
 551
 552        public override void Write(ReadOnlySpan<byte> buffer)
 0553        {
 0554            if (GetType() != typeof(DeflateStream))
 0555            {
 556                // DeflateStream is not sealed, and a derived type may have overridden Write(byte[], int, int) prior
 557                // to this Write(ReadOnlySpan<byte>) overload being introduced.  In that case, this Write(ReadOnlySpan<b
 558                // should use the behavior of Write(byte[],int,int) overload.
 0559                base.Write(buffer);
 0560            }
 561            else
 0562            {
 0563                WriteCore(buffer);
 0564            }
 0565        }
 566
 567        internal void WriteCore(ReadOnlySpan<byte> buffer)
 0568        {
 0569            EnsureCompressionMode();
 0570            EnsureNotDisposed();
 571
 0572            if (buffer.IsEmpty)
 0573            {
 0574                return;
 575            }
 576
 577            // Write compressed the bytes we already passed to the deflater:
 0578            Debug.Assert(_deflater != null);
 0579            WriteDeflaterOutput();
 580
 581            unsafe
 0582            {
 583                // Pass new bytes through deflater and write them too:
 0584                fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer))
 0585                {
 0586                    _deflater.SetInput(bufferPtr, buffer.Length);
 0587                    WriteDeflaterOutput();
 0588                }
 0589            }
 0590        }
 591
 592        private void WriteDeflaterOutput()
 0593        {
 0594            Debug.Assert(_deflater != null && _buffer != null);
 0595            while (!_deflater.NeedsInput())
 0596            {
 0597                int compressedBytes = _deflater.GetDeflateOutput(_buffer);
 0598                if (compressedBytes > 0)
 0599                {
 0600                    _stream.Write(_buffer, 0, compressedBytes);
 0601                }
 0602            }
 0603        }
 604
 605        // This is called by Flush:
 606        private void FlushBuffers()
 0607        {
 608            // Compress any bytes left:
 0609            WriteDeflaterOutput();
 610
 0611            Debug.Assert(_deflater != null && _buffer != null);
 612            // Pull out any bytes left inside deflater:
 613            bool flushSuccessful;
 614            do
 0615            {
 616                int compressedBytes;
 0617                flushSuccessful = _deflater.Flush(_buffer, out compressedBytes);
 0618                if (flushSuccessful)
 0619                {
 0620                    _stream.Write(_buffer, 0, compressedBytes);
 0621                }
 0622                Debug.Assert(flushSuccessful == (compressedBytes > 0));
 0623            } while (flushSuccessful);
 624
 625            // Always flush on the underlying stream
 0626            _stream.Flush();
 0627        }
 628
 629        // This is called by Dispose:
 630        private void PurgeBuffers(bool disposing)
 0631        {
 0632            if (!disposing)
 0633                return;
 634
 0635            if (_stream == null)
 0636                return;
 637
 0638            if (_mode != CompressionMode.Compress)
 0639                return;
 640
 0641            Debug.Assert(_deflater != null && _buffer != null);
 642            // Compress any bytes left
 0643            WriteDeflaterOutput();
 644
 645            // Pull out any bytes left inside deflater:
 646            bool finished;
 647            do
 0648            {
 649                int compressedBytes;
 0650                finished = _deflater.Finish(_buffer, out compressedBytes);
 651
 0652                if (compressedBytes > 0)
 0653                    _stream.Write(_buffer, 0, compressedBytes);
 0654            } while (!finished);
 0655        }
 656
 657        private async ValueTask PurgeBuffersAsync()
 0658        {
 659            // Same logic as PurgeBuffers, except with async counterparts.
 660
 0661            if (_stream == null)
 0662                return;
 663
 0664            if (_mode != CompressionMode.Compress)
 0665                return;
 666
 0667            Debug.Assert(_deflater != null && _buffer != null);
 668            // Compress any bytes left
 0669            await WriteDeflaterOutputAsync(default).ConfigureAwait(false);
 670
 671            // Pull out any bytes left inside deflater:
 672            bool finished;
 673            do
 0674            {
 675                int compressedBytes;
 0676                finished = _deflater.Finish(_buffer, out compressedBytes);
 677
 0678                if (compressedBytes > 0)
 0679                    await _stream.WriteAsync(new ReadOnlyMemory<byte>(_buffer, 0, compressedBytes)).ConfigureAwait(false
 0680            } while (!finished);
 0681        }
 682
 683        /// <summary>
 684        /// Rewinds the underlying stream to the exact end of the compressed data if there are unconsumed bytes.
 685        /// This is called when decompression finishes to reset the stream position.
 686        /// </summary>
 687        private void TryRewindStream(Stream stream)
 0688        {
 0689            Debug.Assert(stream != null);
 0690            Debug.Assert(_mode == CompressionMode.Decompress);
 0691            Debug.Assert(stream.CanSeek);
 0692            Debug.Assert(_inflater != null);
 693
 694            // Check if there are unconsumed bytes in the inflater's input buffer
 0695            int unconsumedBytes = _inflater.GetAvailableInput();
 0696            if (unconsumedBytes > 0)
 0697            {
 698                try
 0699                {
 700                    // Rewind the stream to the exact end of the compressed data
 0701                    stream.Seek(-unconsumedBytes, SeekOrigin.Current);
 0702                }
 0703                catch
 0704                {
 705                    // If seeking fails, we don't want to throw during disposal
 0706                }
 0707            }
 0708        }
 709
 710        protected override void Dispose(bool disposing)
 0711        {
 712            try
 0713            {
 0714                PurgeBuffers(disposing);
 0715            }
 716            finally
 0717            {
 718                // Close the underlying stream even if PurgeBuffers threw.
 719                // Stream.Close() may throw here (may or may not be due to the same error).
 720                // In this case, we still need to clean up internal resources, hence the inner finally blocks.
 721                try
 0722                {
 0723                    if (disposing && !_leaveOpen)
 0724                    {
 0725                        _stream?.Dispose();
 0726                    }
 0727                }
 728                finally
 0729                {
 0730                    _stream = null!;
 731
 732                    try
 0733                    {
 0734                        _deflater?.Dispose();
 0735                        _inflater?.Dispose();
 0736                    }
 737                    finally
 0738                    {
 0739                        _deflater = null;
 0740                        _inflater = null;
 741
 0742                        byte[]? buffer = _buffer;
 0743                        if (buffer != null)
 0744                        {
 0745                            _buffer = null;
 0746                            if (!_activeAsyncOperation)
 0747                            {
 0748                                ArrayPool<byte>.Shared.Return(buffer);
 0749                            }
 0750                        }
 751
 0752                        base.Dispose(disposing);
 0753                    }
 0754                }
 0755            }
 0756        }
 757
 758        public override ValueTask DisposeAsync()
 0759        {
 0760            return GetType() == typeof(DeflateStream) ?
 0761                Core() :
 0762                base.DisposeAsync();
 763
 764            async ValueTask Core()
 0765            {
 766                // Same logic as Dispose(true), except with async counterparts.
 767                try
 0768                {
 0769                    await PurgeBuffersAsync().ConfigureAwait(false);
 0770                }
 771                finally
 0772                {
 773                    // Close the underlying stream even if PurgeBuffers threw.
 774                    // Stream.Close() may throw here (may or may not be due to the same error).
 775                    // In this case, we still need to clean up internal resources, hence the inner finally blocks.
 0776                    Stream stream = _stream;
 0777                    _stream = null!;
 778                    try
 0779                    {
 0780                        if (!_leaveOpen && stream != null)
 0781                        {
 0782                            await stream.DisposeAsync().ConfigureAwait(false);
 0783                        }
 0784                    }
 785                    finally
 0786                    {
 787                        try
 0788                        {
 0789                            _deflater?.Dispose();
 0790                            _inflater?.Dispose();
 0791                        }
 792                        finally
 0793                        {
 0794                            _deflater = null;
 0795                            _inflater = null;
 796
 0797                            byte[]? buffer = _buffer;
 0798                            if (buffer != null)
 0799                            {
 0800                                _buffer = null;
 0801                                if (!_activeAsyncOperation)
 0802                                {
 0803                                    ArrayPool<byte>.Shared.Return(buffer);
 0804                                }
 0805                            }
 0806                        }
 0807                    }
 0808                }
 809            }
 0810        }
 811
 812        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, obje
 0813            TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState
 814
 815        public override void EndWrite(IAsyncResult asyncResult)
 0816        {
 0817            EnsureCompressionMode();
 0818            EnsureNotDisposed();
 0819            TaskToAsyncResult.End(asyncResult);
 0820        }
 821
 822        public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
 0823        {
 0824            ValidateBufferArguments(buffer, offset, count);
 0825            return WriteAsyncMemory(new ReadOnlyMemory<byte>(buffer, offset, count), cancellationToken).AsTask();
 0826        }
 827
 828        public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
 0829        {
 0830            if (GetType() != typeof(DeflateStream))
 0831            {
 832                // Ensure that existing streams derived from DeflateStream and that override WriteAsync(byte[],...)
 833                // get their existing behaviors when the newer Memory-based overload is used.
 0834                return base.WriteAsync(buffer, cancellationToken);
 835            }
 836            else
 0837            {
 0838                return WriteAsyncMemory(buffer, cancellationToken);
 839            }
 0840        }
 841
 842        internal ValueTask WriteAsyncMemory(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
 0843        {
 0844            EnsureCompressionMode();
 0845            EnsureNoActiveAsyncOperation();
 0846            EnsureNotDisposed();
 847
 0848            return
 0849                cancellationToken.IsCancellationRequested ? ValueTask.FromCanceled(cancellationToken) :
 0850                buffer.IsEmpty ? default :
 0851                Core(buffer, cancellationToken);
 852
 853            async ValueTask Core(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
 0854            {
 0855                AsyncOperationStarting();
 856                try
 0857                {
 0858                    await WriteDeflaterOutputAsync(cancellationToken).ConfigureAwait(false);
 859
 860                    // Pass new bytes through deflater
 0861                    Debug.Assert(_deflater != null);
 0862                    _deflater.SetInput(buffer);
 863
 0864                    await WriteDeflaterOutputAsync(cancellationToken).ConfigureAwait(false);
 0865                }
 866                finally
 0867                {
 0868                    AsyncOperationCompleting();
 0869                }
 0870            }
 0871        }
 872
 873        /// <summary>
 874        /// Writes the bytes that have already been deflated
 875        /// </summary>
 876        private async ValueTask WriteDeflaterOutputAsync(CancellationToken cancellationToken)
 0877        {
 0878            Debug.Assert(_deflater != null && _buffer != null);
 0879            while (!_deflater.NeedsInput())
 0880            {
 0881                int compressedBytes = _deflater.GetDeflateOutput(_buffer);
 0882                if (compressedBytes > 0)
 0883                {
 0884                    await _stream.WriteAsync(new ReadOnlyMemory<byte>(_buffer, 0, compressedBytes), cancellationToken).C
 0885                }
 0886            }
 0887        }
 888
 889        public override void CopyTo(Stream destination, int bufferSize)
 0890        {
 0891            ValidateCopyToArguments(destination, bufferSize);
 892
 0893            EnsureNotDisposed();
 0894            if (!CanRead) throw new NotSupportedException();
 895
 0896            new CopyToStream(this, destination, bufferSize).CopyFromSourceToDestination();
 0897        }
 898
 899        public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
 0900        {
 0901            ValidateCopyToArguments(destination, bufferSize);
 902
 0903            EnsureNotDisposed();
 0904            if (!CanRead) throw new NotSupportedException();
 0905            EnsureNoActiveAsyncOperation();
 906
 907            // Early check for cancellation
 0908            if (cancellationToken.IsCancellationRequested)
 0909            {
 0910                return Task.FromCanceled<int>(cancellationToken);
 911            }
 912
 913            // Do the copy
 0914            return new CopyToStream(this, destination, bufferSize, cancellationToken).CopyFromSourceToDestinationAsync()
 0915        }
 916
 917        private sealed class CopyToStream : Stream
 918        {
 919            private readonly DeflateStream _deflateStream;
 920            private readonly Stream _destination;
 921            private readonly CancellationToken _cancellationToken;
 922            private byte[] _arrayPoolBuffer;
 923
 924            public CopyToStream(DeflateStream deflateStream, Stream destination, int bufferSize) :
 0925                this(deflateStream, destination, bufferSize, CancellationToken.None)
 0926            {
 0927            }
 928
 0929            public CopyToStream(DeflateStream deflateStream, Stream destination, int bufferSize, CancellationToken cance
 0930            {
 0931                Debug.Assert(deflateStream != null);
 0932                Debug.Assert(destination != null);
 0933                Debug.Assert(bufferSize > 0);
 934
 0935                _deflateStream = deflateStream;
 0936                _destination = destination;
 0937                _cancellationToken = cancellationToken;
 0938                _arrayPoolBuffer = ArrayPool<byte>.Shared.Rent(bufferSize);
 0939            }
 940
 941            public async Task CopyFromSourceToDestinationAsync()
 0942            {
 0943                _deflateStream.AsyncOperationStarting();
 944                try
 0945                {
 0946                    Debug.Assert(_deflateStream._inflater != null);
 947                    // Flush any existing data in the inflater to the destination stream.
 0948                    while (!_deflateStream._inflater.Finished())
 0949                    {
 0950                        int bytesRead = _deflateStream._inflater.Inflate(_arrayPoolBuffer, 0, _arrayPoolBuffer.Length);
 0951                        if (bytesRead > 0)
 0952                        {
 0953                            await _destination.WriteAsync(new ReadOnlyMemory<byte>(_arrayPoolBuffer, 0, bytesRead), _can
 0954                        }
 0955                        else if (_deflateStream._inflater.NeedsInput())
 0956                        {
 957                            // only break if we read 0 and ran out of input, if input is still available it may be anoth
 0958                            break;
 959                        }
 0960                    }
 961
 962                    // Now, use the source stream's CopyToAsync to push directly to our inflater via this helper stream
 0963                    await _deflateStream._stream.CopyToAsync(this, _arrayPoolBuffer.Length, _cancellationToken).Configur
 0964                    if (s_useStrictValidation && !_deflateStream._inflater.Finished())
 0965                    {
 0966                        ThrowTruncatedInvalidData();
 0967                    }
 968
 969                    // Rewind the stream if decompression has finished and the stream supports seeking
 0970                    if (_deflateStream._inflater.Finished() && !_deflateStream._decompressionFinished && _deflateStream.
 0971                    {
 0972                        _deflateStream.TryRewindStream(_deflateStream._stream);
 0973                        _deflateStream._decompressionFinished = true;
 0974                    }
 0975                }
 976                finally
 0977                {
 0978                    _deflateStream.AsyncOperationCompleting();
 979
 0980                    ArrayPool<byte>.Shared.Return(_arrayPoolBuffer);
 0981                    _arrayPoolBuffer = null!;
 0982                }
 0983            }
 984
 985            public void CopyFromSourceToDestination()
 0986            {
 987                try
 0988                {
 0989                    Debug.Assert(_deflateStream._inflater != null);
 990                    // Flush any existing data in the inflater to the destination stream.
 0991                    while (!_deflateStream._inflater.Finished())
 0992                    {
 0993                        int bytesRead = _deflateStream._inflater.Inflate(_arrayPoolBuffer, 0, _arrayPoolBuffer.Length);
 0994                        if (bytesRead > 0)
 0995                        {
 0996                            _destination.Write(_arrayPoolBuffer, 0, bytesRead);
 0997                        }
 0998                        else if (_deflateStream._inflater.NeedsInput())
 0999                        {
 1000                            // only break if we read 0 and ran out of input, if input is still available it may be anoth
 01001                            break;
 1002                        }
 01003                    }
 1004
 1005                    // Now, use the source stream's CopyToAsync to push directly to our inflater via this helper stream
 01006                    _deflateStream._stream.CopyTo(this, _arrayPoolBuffer.Length);
 01007                    if (s_useStrictValidation && !_deflateStream._inflater.Finished())
 01008                    {
 01009                        ThrowTruncatedInvalidData();
 01010                    }
 1011
 1012                    // Rewind the stream if decompression has finished and the stream supports seeking
 01013                    if (_deflateStream._inflater.Finished() && !_deflateStream._decompressionFinished && _deflateStream.
 01014                    {
 01015                        _deflateStream.TryRewindStream(_deflateStream._stream);
 01016                        _deflateStream._decompressionFinished = true;
 01017                    }
 01018                }
 1019                finally
 01020                {
 01021                    ArrayPool<byte>.Shared.Return(_arrayPoolBuffer);
 01022                    _arrayPoolBuffer = null!;
 01023                }
 01024            }
 1025
 1026            public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
 01027            {
 01028                Debug.Assert(buffer != _arrayPoolBuffer);
 01029                _deflateStream.EnsureNotDisposed();
 01030                if (count <= 0)
 01031                {
 01032                    return Task.CompletedTask;
 1033                }
 01034                else if (count > buffer.Length - offset)
 01035                {
 1036                    // The buffer stream is either malicious or poorly implemented and returned a number of
 1037                    // bytes larger than the buffer supplied to it.
 01038                    return Task.FromException(new InvalidDataException(SR.GenericInvalidData));
 1039                }
 1040
 01041                return WriteAsyncCore(buffer.AsMemory(offset, count), cancellationToken).AsTask();
 01042            }
 1043
 1044            public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = defa
 01045            {
 01046                _deflateStream.EnsureNotDisposed();
 1047
 01048                return WriteAsyncCore(buffer, cancellationToken);
 01049            }
 1050
 1051            private async ValueTask WriteAsyncCore(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
 01052            {
 01053                Debug.Assert(_deflateStream._inflater is not null);
 1054
 1055                // Feed the data from base stream into decompression engine.
 01056                _deflateStream._inflater.SetInput(buffer);
 1057
 1058                // While there's more decompressed data available, forward it to the buffer stream.
 01059                while (!_deflateStream._inflater.Finished())
 01060                {
 01061                    int bytesRead = _deflateStream._inflater.Inflate(new Span<byte>(_arrayPoolBuffer));
 01062                    if (bytesRead > 0)
 01063                    {
 01064                        await _destination.WriteAsync(new ReadOnlyMemory<byte>(_arrayPoolBuffer, 0, bytesRead), cancella
 01065                    }
 01066                    else if (_deflateStream._inflater.NeedsInput())
 01067                    {
 1068                        // only break if we read 0 and ran out of input, if input is still available it may be another G
 01069                        break;
 1070                    }
 01071                }
 01072            }
 1073
 1074            public override void Write(byte[] buffer, int offset, int count)
 01075            {
 01076                Debug.Assert(buffer != _arrayPoolBuffer);
 01077                _deflateStream.EnsureNotDisposed();
 1078
 01079                if (count <= 0)
 01080                {
 01081                    return;
 1082                }
 01083                else if (count > buffer.Length - offset)
 01084                {
 1085                    // The buffer stream is either malicious or poorly implemented and returned a number of
 1086                    // bytes larger than the buffer supplied to it.
 01087                    throw new InvalidDataException(SR.GenericInvalidData);
 1088                }
 1089
 01090                Debug.Assert(_deflateStream._inflater != null);
 1091                // Feed the data from base stream into the decompression engine.
 01092                _deflateStream._inflater.SetInput(buffer, offset, count);
 1093
 1094                // While there's more decompressed data available, forward it to the buffer stream.
 01095                while (!_deflateStream._inflater.Finished())
 01096                {
 01097                    int bytesRead = _deflateStream._inflater.Inflate(new Span<byte>(_arrayPoolBuffer));
 01098                    if (bytesRead > 0)
 01099                    {
 01100                        _destination.Write(_arrayPoolBuffer, 0, bytesRead);
 01101                    }
 01102                    else if (_deflateStream._inflater.NeedsInput())
 01103                    {
 1104                        // only break if we read 0 and ran out of input, if input is still available it may be another G
 01105                        break;
 1106                    }
 01107                }
 01108            }
 1109
 01110            public override bool CanWrite => true;
 01111            public override void Flush() { }
 01112            public override bool CanRead => false;
 01113            public override bool CanSeek => false;
 01114            public override long Length { get { throw new NotSupportedException(); } }
 01115            public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedExcep
 01116            public override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException(); }
 01117            public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); }
 01118            public override void SetLength(long value) { throw new NotSupportedException(); }
 1119        }
 1120
 1121        private void EnsureNoActiveAsyncOperation()
 01122        {
 01123            if (_activeAsyncOperation)
 01124            {
 01125                ThrowInvalidBeginCall();
 01126            }
 01127        }
 1128
 1129        private void AsyncOperationStarting()
 01130        {
 01131            if (Interlocked.Exchange(ref _activeAsyncOperation, true))
 01132            {
 01133                ThrowInvalidBeginCall();
 01134            }
 01135        }
 1136
 1137        private void AsyncOperationCompleting()
 01138        {
 01139            Debug.Assert(_activeAsyncOperation);
 01140            _activeAsyncOperation = false;
 01141        }
 1142
 1143        private static void ThrowInvalidBeginCall() =>
 01144            throw new InvalidOperationException(SR.InvalidBeginCall);
 1145
 01146        private static readonly bool s_useStrictValidation =
 01147            AppContext.TryGetSwitch("System.IO.Compression.UseStrictValidation", out bool strictValidation) ? strictVali
 1148    }
 1149}

Methods/Properties

.ctor(System.IO.Stream,System.IO.Compression.CompressionMode,System.Int64)
.ctor(System.IO.Stream,System.IO.Compression.CompressionMode)
.ctor(System.IO.Stream,System.IO.Compression.CompressionMode,System.Boolean)
.ctor(System.IO.Stream,System.IO.Compression.CompressionLevel)
.ctor(System.IO.Stream,System.IO.Compression.CompressionLevel,System.Boolean)
.ctor(System.IO.Stream,System.IO.Compression.ZLibCompressionOptions,System.Boolean)
.ctor(System.IO.Stream,System.IO.Compression.ZLibCompressionOptions,System.Boolean,System.Int32)
.ctor(System.IO.Stream,System.IO.Compression.CompressionMode,System.Boolean,System.Int32,System.Int64)
.ctor(System.IO.Stream,System.IO.Compression.CompressionLevel,System.Boolean,System.Int32)
InitializeDeflater(System.IO.Stream,System.IO.Compression.ZLibNative/CompressionLevel,System.IO.Compression.ZLibNative/CompressionStrategy,System.Boolean,System.Int32)
GetZLibNativeCompressionLevel(System.IO.Compression.CompressionLevel)
GetMemLevel(System.IO.Compression.ZLibNative/CompressionLevel)
InitializeBuffer()
EnsureBufferInitialized()
BaseStream()
CanRead()
CanWrite()
CanSeek()
Length()
Position()
Position(System.Int64)
Flush()
FlushAsync(System.Threading.CancellationToken)
Core(System.Threading.CancellationToken)
Seek(System.Int64,System.IO.SeekOrigin)
SetLength(System.Int64)
ReadByte()
Read(System.Byte[],System.Int32,System.Int32)
Read(System.Span`1<System.Byte>)
ReadCore(System.Span`1<System.Byte>)
InflatorIsFinished()
EnsureNotDisposed()
EnsureDecompressionMode()
ThrowCannotReadFromDeflateStreamException()
EnsureCompressionMode()
ThrowCannotWriteToDeflateStreamException()
ThrowGenericInvalidData()
ThrowTruncatedInvalidData()
BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)
EndRead(System.IAsyncResult)
ReadAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)
ReadAsync(System.Memory`1<System.Byte>,System.Threading.CancellationToken)
ReadAsyncMemory(System.Memory`1<System.Byte>,System.Threading.CancellationToken)
Core(System.Memory`1<System.Byte>,System.Threading.CancellationToken)
Write(System.Byte[],System.Int32,System.Int32)
WriteByte(System.Byte)
Write(System.ReadOnlySpan`1<System.Byte>)
WriteCore(System.ReadOnlySpan`1<System.Byte>)
WriteDeflaterOutput()
FlushBuffers()
PurgeBuffers(System.Boolean)
PurgeBuffersAsync()
TryRewindStream(System.IO.Stream)
Dispose(System.Boolean)
DisposeAsync()
Core()
BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)
EndWrite(System.IAsyncResult)
WriteAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)
WriteAsync(System.ReadOnlyMemory`1<System.Byte>,System.Threading.CancellationToken)
WriteAsyncMemory(System.ReadOnlyMemory`1<System.Byte>,System.Threading.CancellationToken)
Core(System.ReadOnlyMemory`1<System.Byte>,System.Threading.CancellationToken)
WriteDeflaterOutputAsync(System.Threading.CancellationToken)
CopyTo(System.IO.Stream,System.Int32)
CopyToAsync(System.IO.Stream,System.Int32,System.Threading.CancellationToken)
.ctor(System.IO.Compression.DeflateStream,System.IO.Stream,System.Int32)
.ctor(System.IO.Compression.DeflateStream,System.IO.Stream,System.Int32,System.Threading.CancellationToken)
CopyFromSourceToDestinationAsync()
CopyFromSourceToDestination()
WriteAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)
WriteAsync(System.ReadOnlyMemory`1<System.Byte>,System.Threading.CancellationToken)
WriteAsyncCore(System.ReadOnlyMemory`1<System.Byte>,System.Threading.CancellationToken)
Write(System.Byte[],System.Int32,System.Int32)
CanWrite()
Flush()
CanRead()
CanSeek()
Length()
Position()
Read(System.Byte[],System.Int32,System.Int32)
Seek(System.Int64,System.IO.SeekOrigin)
SetLength(System.Int64)
EnsureNoActiveAsyncOperation()
AsyncOperationStarting()
AsyncOperationCompleting()
ThrowInvalidBeginCall()
.cctor()