< 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
59%
Covered lines: 405
Uncovered lines: 274
Coverable lines: 679
Total lines: 1149
Line coverage: 59.6%
Branch coverage
53%
Covered branches: 139
Total branches: 259
Branch coverage: 53.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
.ctor(...)100%110%
.ctor(...)100%110%
.ctor(...)100%110%
.ctor(...)100%11100%
.ctor(...)100%110%
.ctor(...)100%110%
.ctor(...)33.33%6673.33%
.ctor(...)100%11100%
InitializeDeflater(...)50%2290%
GetZLibNativeCompressionLevel(...)20%5550%
GetMemLevel(...)50%22100%
InitializeBuffer()100%11100%
EnsureBufferInitialized()100%22100%
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(...)50%2271.42%
ReadCore(...)57.14%282860.97%
EnsureNotDisposed()100%11100%
EnsureDecompressionMode()50%2275%
ThrowCannotReadFromDeflateStreamException()100%110%
EnsureCompressionMode()50%2275%
ThrowCannotWriteToDeflateStreamException()100%110%
ThrowGenericInvalidData()100%110%
ThrowTruncatedInvalidData()100%110%
BeginRead(...)100%110%
EndRead(...)100%110%
ReadAsync(...)100%110%
ReadAsync(...)50%2271.42%
ReadAsyncMemory(...)50%2281.81%
Core(System.Memory`1<System.Byte>,System.Threading.CancellationToken)60.71%282863.41%
Write(...)100%110%
WriteByte(...)0%220%
Write(...)50%2266.66%
WriteCore(...)50%2287.5%
WriteDeflaterOutput()66.66%6672.72%
FlushBuffers()0%660%
PurgeBuffers(...)75%121286.66%
PurgeBuffersAsync()70%101092.3%
TryRewindStream(...)0%220%
Dispose(...)85.71%1414100%
DisposeAsync()50%22100%
Core()81.25%1616100%
BeginWrite(...)100%110%
EndWrite(...)100%110%
WriteAsync(...)100%110%
WriteAsync(...)50%2271.42%
WriteAsyncMemory(...)50%44100%
Core(System.ReadOnlyMemory`1<System.Byte>,System.Threading.CancellationToken)100%11100%
WriteDeflaterOutputAsync(...)66.66%6672.72%
CopyTo(...)50%22100%
CopyToAsync(...)50%4480%
.ctor(...)100%11100%
.ctor(...)100%11100%
CopyFromSourceToDestinationAsync()56.25%161665.62%
CopyFromSourceToDestination()56.25%161663.33%
WriteAsync(...)0%440%
WriteAsync(...)100%11100%
WriteAsyncCore(...)66.66%6680%
Write(...)60%101069.56%
Flush()100%110%
Read(...)100%110%
Seek(...)100%110%
SetLength(...)100%110%
EnsureNoActiveAsyncOperation()50%2250%
AsyncOperationStarting()50%2250%
AsyncOperationCompleting()100%11100%
ThrowInvalidBeginCall()100%110%
.cctor()50%22100%

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
 82127        internal DeflateStream(Stream stream, CompressionMode mode, long uncompressedSize) : this(stream, mode, leaveOpe
 82128        {
 82129        }
 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
 81845        public DeflateStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen) : this(stream, compressio
 81846        {
 81847        }
 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>
 82178        internal DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen, int windowBits, long uncompressedSiz
 82179        {
 82180            ArgumentNullException.ThrowIfNull(stream);
 81
 82182            switch (mode)
 83            {
 84                case CompressionMode.Decompress:
 82185                    if (!stream.CanRead)
 086                        throw new ArgumentException(SR.NotSupported_UnreadableStream, nameof(stream));
 87
 82188                    _inflater = Inflater.CreateInflater(windowBits, uncompressedSize);
 82189                    _stream = stream;
 82190                    _mode = CompressionMode.Decompress;
 82191                    _leaveOpen = leaveOpen;
 82192                    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            }
 821101        }
 102
 103        /// <summary>
 104        /// Internal constructor to specify the compressionLevel as well as the windowBits
 105        /// </summary>
 818106        internal DeflateStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen, int windowBits)
 818107        {
 818108            ArgumentNullException.ThrowIfNull(stream);
 109
 818110            InitializeDeflater(stream, GetZLibNativeCompressionLevel(compressionLevel), CompressionStrategy.DefaultStrat
 818111        }
 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
 818118        {
 818119            Debug.Assert(stream != null);
 818120            if (!stream.CanWrite)
 0121                throw new ArgumentException(SR.NotSupported_UnwritableStream, nameof(stream));
 122
 818123            _deflater = Deflater.CreateDeflater(compressionLevel, strategy, windowBits, GetMemLevel(compressionLevel));
 124
 818125            _stream = stream;
 818126            _mode = CompressionMode.Compress;
 818127            _leaveOpen = leaveOpen;
 818128            InitializeBuffer();
 818129        }
 130
 131        private static ZLibNative.CompressionLevel GetZLibNativeCompressionLevel(CompressionLevel compressionLevel) =>
 818132            compressionLevel switch
 818133            {
 818134                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)),
 818139            };
 140
 141        private static int GetMemLevel(ZLibNative.CompressionLevel level) =>
 818142            level == ZLibNative.CompressionLevel.NoCompression ?
 818143                Deflate_NoCompressionMemLevel :
 818144                Deflate_DefaultMemLevel;
 145
 146        [MemberNotNull(nameof(_buffer))]
 147        private void InitializeBuffer()
 1545148        {
 1545149            Debug.Assert(_buffer == null);
 1545150            _buffer = ArrayPool<byte>.Shared.Rent(DefaultBufferSize);
 1545151        }
 152
 153        [MemberNotNull(nameof(_buffer))]
 154        private void EnsureBufferInitialized()
 1451155        {
 1451156            if (_buffer == null)
 727157            {
 727158                InitializeBuffer();
 727159            }
 1451160        }
 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
 821174            {
 821175                if (_stream == null)
 0176                {
 0177                    return false;
 178                }
 179
 821180                return (_mode == CompressionMode.Decompress && _stream.CanRead);
 821181            }
 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
 821197        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)
 725291        {
 725292            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
 725300            {
 725301                return ReadCore(buffer);
 302            }
 724303        }
 304
 305        internal int ReadCore(Span<byte> buffer)
 725306        {
 725307            EnsureDecompressionMode();
 725308            EnsureNotDisposed();
 725309            EnsureBufferInitialized();
 725310            Debug.Assert(_inflater != null);
 311
 312            int bytesRead;
 1088313            while (true)
 1088314            {
 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.
 1088317                bytesRead = _inflater.Inflate(buffer);
 1087318                if (bytesRead != 0 || InflatorIsFinished)
 724319                {
 724320                    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.
 363325                if (_inflater.NeedsInput())
 363326                {
 363327                    int n = _stream.Read(_buffer, 0, _buffer.Length);
 363328                    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                    }
 363341                    else if (n > _buffer.Length)
 0342                    {
 0343                        ThrowGenericInvalidData();
 0344                    }
 345                    else
 363346                    {
 363347                        _inflater.SetInput(_buffer, 0, n);
 363348                    }
 363349                }
 350
 363351                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                }
 363362            }
 363
 364            // When decompression finishes, rewind the stream to the exact end of compressed data
 724365            if (bytesRead == 0 && InflatorIsFinished && !_decompressionFinished && _stream.CanSeek)
 0366            {
 0367                TryRewindStream(_stream);
 0368                _decompressionFinished = true;
 0369            }
 370
 724371            return bytesRead;
 724372        }
 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
 2175379            _inflater!.Finished() &&
 2175380            (!_inflater.IsGzipStream() || !_inflater.NeedsInput());
 381
 382        private void EnsureNotDisposed()
 2457383        {
 2457384            ObjectDisposedException.ThrowIf(_stream is null, this);
 2457385        }
 386
 387        private void EnsureDecompressionMode()
 1451388        {
 1451389            if (_mode != CompressionMode.Decompress)
 0390                ThrowCannotReadFromDeflateStreamException();
 391
 392            static void ThrowCannotReadFromDeflateStreamException() =>
 0393                throw new InvalidOperationException(SR.CannotReadFromDeflateStream);
 1451394        }
 395
 396        private void EnsureCompressionMode()
 818397        {
 818398            if (_mode != CompressionMode.Compress)
 0399                ThrowCannotWriteToDeflateStreamException();
 400
 401            static void ThrowCannotWriteToDeflateStreamException() =>
 0402                throw new InvalidOperationException(SR.CannotWriteToDeflateStream);
 818403        }
 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)
 726430        {
 726431            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
 726438            {
 726439                return ReadAsyncMemory(buffer, cancellationToken);
 440            }
 726441        }
 442
 443        internal ValueTask<int> ReadAsyncMemory(Memory<byte> buffer, CancellationToken cancellationToken)
 726444        {
 726445            EnsureDecompressionMode();
 726446            EnsureNoActiveAsyncOperation();
 726447            EnsureNotDisposed();
 448
 726449            if (cancellationToken.IsCancellationRequested)
 0450            {
 0451                return ValueTask.FromCanceled<int>(cancellationToken);
 452            }
 453
 726454            EnsureBufferInitialized();
 726455            Debug.Assert(_inflater != null);
 456
 726457            return Core(buffer, cancellationToken);
 458
 459            async ValueTask<int> Core(Memory<byte> buffer, CancellationToken cancellationToken)
 726460            {
 726461                AsyncOperationStarting();
 462                try
 726463                {
 464                    int bytesRead;
 1090465                    while (true)
 1090466                    {
 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.
 1090469                        bytesRead = _inflater.Inflate(buffer.Span);
 1088470                        if (bytesRead != 0 || InflatorIsFinished)
 724471                        {
 724472                            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.
 364477                        if (_inflater.NeedsInput())
 364478                        {
 364479                            int n = await _stream.ReadAsync(new Memory<byte>(_buffer, 0, _buffer.Length), cancellationTo
 364480                            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                            }
 364493                            else if (n > _buffer.Length)
 0494                            {
 0495                                ThrowGenericInvalidData();
 0496                            }
 497                            else
 364498                            {
 364499                                _inflater.SetInput(_buffer, 0, n);
 364500                            }
 364501                        }
 502
 364503                        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                        }
 364513                    }
 514
 515                    // When decompression finishes, rewind the stream to the exact end of compressed data
 724516                    if (bytesRead == 0 && InflatorIsFinished && !_decompressionFinished && _stream.CanSeek)
 0517                    {
 0518                        TryRewindStream(_stream);
 0519                        _decompressionFinished = true;
 0520                    }
 521
 724522                    return bytesRead;
 523                }
 524                finally
 726525                {
 726526                    AsyncOperationCompleting();
 726527                }
 724528            }
 726529        }
 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)
 409553        {
 409554            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
 409562            {
 409563                WriteCore(buffer);
 409564            }
 409565        }
 566
 567        internal void WriteCore(ReadOnlySpan<byte> buffer)
 409568        {
 409569            EnsureCompressionMode();
 409570            EnsureNotDisposed();
 571
 409572            if (buffer.IsEmpty)
 0573            {
 0574                return;
 575            }
 576
 577            // Write compressed the bytes we already passed to the deflater:
 409578            Debug.Assert(_deflater != null);
 409579            WriteDeflaterOutput();
 580
 581            unsafe
 409582            {
 583                // Pass new bytes through deflater and write them too:
 409584                fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer))
 409585                {
 409586                    _deflater.SetInput(bufferPtr, buffer.Length);
 409587                    WriteDeflaterOutput();
 409588                }
 409589            }
 409590        }
 591
 592        private void WriteDeflaterOutput()
 1227593        {
 1227594            Debug.Assert(_deflater != null && _buffer != null);
 1636595            while (!_deflater.NeedsInput())
 409596            {
 409597                int compressedBytes = _deflater.GetDeflateOutput(_buffer);
 409598                if (compressedBytes > 0)
 0599                {
 0600                    _stream.Write(_buffer, 0, compressedBytes);
 0601                }
 409602            }
 1227603        }
 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)
 819631        {
 819632            if (!disposing)
 0633                return;
 634
 819635            if (_stream == null)
 0636                return;
 637
 819638            if (_mode != CompressionMode.Compress)
 410639                return;
 640
 409641            Debug.Assert(_deflater != null && _buffer != null);
 642            // Compress any bytes left
 409643            WriteDeflaterOutput();
 644
 645            // Pull out any bytes left inside deflater:
 646            bool finished;
 647            do
 409648            {
 649                int compressedBytes;
 409650                finished = _deflater.Finish(_buffer, out compressedBytes);
 651
 409652                if (compressedBytes > 0)
 409653                    _stream.Write(_buffer, 0, compressedBytes);
 818654            } while (!finished);
 819655        }
 656
 657        private async ValueTask PurgeBuffersAsync()
 820658        {
 659            // Same logic as PurgeBuffers, except with async counterparts.
 660
 820661            if (_stream == null)
 0662                return;
 663
 820664            if (_mode != CompressionMode.Compress)
 411665                return;
 666
 409667            Debug.Assert(_deflater != null && _buffer != null);
 668            // Compress any bytes left
 409669            await WriteDeflaterOutputAsync(default).ConfigureAwait(false);
 670
 671            // Pull out any bytes left inside deflater:
 672            bool finished;
 673            do
 409674            {
 675                int compressedBytes;
 409676                finished = _deflater.Finish(_buffer, out compressedBytes);
 677
 409678                if (compressedBytes > 0)
 409679                    await _stream.WriteAsync(new ReadOnlyMemory<byte>(_buffer, 0, compressedBytes)).ConfigureAwait(false
 818680            } while (!finished);
 820681        }
 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)
 819711        {
 712            try
 819713            {
 819714                PurgeBuffers(disposing);
 819715            }
 716            finally
 819717            {
 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
 819722                {
 819723                    if (disposing && !_leaveOpen)
 457724                    {
 457725                        _stream?.Dispose();
 457726                    }
 819727                }
 728                finally
 819729                {
 819730                    _stream = null!;
 731
 732                    try
 819733                    {
 819734                        _deflater?.Dispose();
 819735                        _inflater?.Dispose();
 819736                    }
 737                    finally
 819738                    {
 819739                        _deflater = null;
 819740                        _inflater = null;
 741
 819742                        byte[]? buffer = _buffer;
 819743                        if (buffer != null)
 772744                        {
 772745                            _buffer = null;
 772746                            if (!_activeAsyncOperation)
 772747                            {
 772748                                ArrayPool<byte>.Shared.Return(buffer);
 772749                            }
 772750                        }
 751
 819752                        base.Dispose(disposing);
 819753                    }
 819754                }
 819755            }
 819756        }
 757
 758        public override ValueTask DisposeAsync()
 820759        {
 820760            return GetType() == typeof(DeflateStream) ?
 820761                Core() :
 820762                base.DisposeAsync();
 763
 764            async ValueTask Core()
 820765            {
 766                // Same logic as Dispose(true), except with async counterparts.
 767                try
 820768                {
 820769                    await PurgeBuffersAsync().ConfigureAwait(false);
 820770                }
 771                finally
 820772                {
 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.
 820776                    Stream stream = _stream;
 820777                    _stream = null!;
 778                    try
 820779                    {
 820780                        if (!_leaveOpen && stream != null)
 458781                        {
 458782                            await stream.DisposeAsync().ConfigureAwait(false);
 458783                        }
 820784                    }
 785                    finally
 820786                    {
 787                        try
 820788                        {
 820789                            _deflater?.Dispose();
 820790                            _inflater?.Dispose();
 820791                        }
 792                        finally
 820793                        {
 820794                            _deflater = null;
 820795                            _inflater = null;
 796
 820797                            byte[]? buffer = _buffer;
 820798                            if (buffer != null)
 773799                            {
 773800                                _buffer = null;
 773801                                if (!_activeAsyncOperation)
 773802                                {
 773803                                    ArrayPool<byte>.Shared.Return(buffer);
 773804                                }
 773805                            }
 820806                        }
 820807                    }
 820808                }
 809            }
 1640810        }
 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)
 409829        {
 409830            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
 409837            {
 409838                return WriteAsyncMemory(buffer, cancellationToken);
 839            }
 409840        }
 841
 842        internal ValueTask WriteAsyncMemory(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
 409843        {
 409844            EnsureCompressionMode();
 409845            EnsureNoActiveAsyncOperation();
 409846            EnsureNotDisposed();
 847
 409848            return
 409849                cancellationToken.IsCancellationRequested ? ValueTask.FromCanceled(cancellationToken) :
 409850                buffer.IsEmpty ? default :
 409851                Core(buffer, cancellationToken);
 852
 853            async ValueTask Core(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
 409854            {
 409855                AsyncOperationStarting();
 856                try
 409857                {
 409858                    await WriteDeflaterOutputAsync(cancellationToken).ConfigureAwait(false);
 859
 860                    // Pass new bytes through deflater
 409861                    Debug.Assert(_deflater != null);
 409862                    _deflater.SetInput(buffer);
 863
 409864                    await WriteDeflaterOutputAsync(cancellationToken).ConfigureAwait(false);
 409865                }
 866                finally
 409867                {
 409868                    AsyncOperationCompleting();
 409869                }
 409870            }
 409871        }
 872
 873        /// <summary>
 874        /// Writes the bytes that have already been deflated
 875        /// </summary>
 876        private async ValueTask WriteDeflaterOutputAsync(CancellationToken cancellationToken)
 1227877        {
 1227878            Debug.Assert(_deflater != null && _buffer != null);
 1636879            while (!_deflater.NeedsInput())
 409880            {
 409881                int compressedBytes = _deflater.GetDeflateOutput(_buffer);
 409882                if (compressedBytes > 0)
 0883                {
 0884                    await _stream.WriteAsync(new ReadOnlyMemory<byte>(_buffer, 0, compressedBytes), cancellationToken).C
 0885                }
 409886            }
 1227887        }
 888
 889        public override void CopyTo(Stream destination, int bufferSize)
 47890        {
 47891            ValidateCopyToArguments(destination, bufferSize);
 892
 47893            EnsureNotDisposed();
 47894            if (!CanRead) throw new NotSupportedException();
 895
 47896            new CopyToStream(this, destination, bufferSize).CopyFromSourceToDestination();
 47897        }
 898
 899        public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
 47900        {
 47901            ValidateCopyToArguments(destination, bufferSize);
 902
 47903            EnsureNotDisposed();
 47904            if (!CanRead) throw new NotSupportedException();
 47905            EnsureNoActiveAsyncOperation();
 906
 907            // Early check for cancellation
 47908            if (cancellationToken.IsCancellationRequested)
 0909            {
 0910                return Task.FromCanceled<int>(cancellationToken);
 911            }
 912
 913            // Do the copy
 47914            return new CopyToStream(this, destination, bufferSize, cancellationToken).CopyFromSourceToDestinationAsync()
 47915        }
 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) :
 47925                this(deflateStream, destination, bufferSize, CancellationToken.None)
 47926            {
 47927            }
 928
 94929            public CopyToStream(DeflateStream deflateStream, Stream destination, int bufferSize, CancellationToken cance
 94930            {
 94931                Debug.Assert(deflateStream != null);
 94932                Debug.Assert(destination != null);
 94933                Debug.Assert(bufferSize > 0);
 934
 94935                _deflateStream = deflateStream;
 94936                _destination = destination;
 94937                _cancellationToken = cancellationToken;
 94938                _arrayPoolBuffer = ArrayPool<byte>.Shared.Rent(bufferSize);
 94939            }
 940
 941            public async Task CopyFromSourceToDestinationAsync()
 47942            {
 47943                _deflateStream.AsyncOperationStarting();
 944                try
 47945                {
 47946                    Debug.Assert(_deflateStream._inflater != null);
 947                    // Flush any existing data in the inflater to the destination stream.
 47948                    while (!_deflateStream._inflater.Finished())
 47949                    {
 47950                        int bytesRead = _deflateStream._inflater.Inflate(_arrayPoolBuffer, 0, _arrayPoolBuffer.Length);
 47951                        if (bytesRead > 0)
 0952                        {
 0953                            await _destination.WriteAsync(new ReadOnlyMemory<byte>(_arrayPoolBuffer, 0, bytesRead), _can
 0954                        }
 47955                        else if (_deflateStream._inflater.NeedsInput())
 47956                        {
 957                            // only break if we read 0 and ran out of input, if input is still available it may be anoth
 47958                            break;
 959                        }
 0960                    }
 961
 962                    // Now, use the source stream's CopyToAsync to push directly to our inflater via this helper stream
 47963                    await _deflateStream._stream.CopyToAsync(this, _arrayPoolBuffer.Length, _cancellationToken).Configur
 47964                    if (s_useStrictValidation && !_deflateStream._inflater.Finished())
 0965                    {
 0966                        ThrowTruncatedInvalidData();
 0967                    }
 968
 969                    // Rewind the stream if decompression has finished and the stream supports seeking
 47970                    if (_deflateStream._inflater.Finished() && !_deflateStream._decompressionFinished && _deflateStream.
 0971                    {
 0972                        _deflateStream.TryRewindStream(_deflateStream._stream);
 0973                        _deflateStream._decompressionFinished = true;
 0974                    }
 47975                }
 976                finally
 47977                {
 47978                    _deflateStream.AsyncOperationCompleting();
 979
 47980                    ArrayPool<byte>.Shared.Return(_arrayPoolBuffer);
 47981                    _arrayPoolBuffer = null!;
 47982                }
 47983            }
 984
 985            public void CopyFromSourceToDestination()
 47986            {
 987                try
 47988                {
 47989                    Debug.Assert(_deflateStream._inflater != null);
 990                    // Flush any existing data in the inflater to the destination stream.
 47991                    while (!_deflateStream._inflater.Finished())
 47992                    {
 47993                        int bytesRead = _deflateStream._inflater.Inflate(_arrayPoolBuffer, 0, _arrayPoolBuffer.Length);
 47994                        if (bytesRead > 0)
 0995                        {
 0996                            _destination.Write(_arrayPoolBuffer, 0, bytesRead);
 0997                        }
 47998                        else if (_deflateStream._inflater.NeedsInput())
 47999                        {
 1000                            // only break if we read 0 and ran out of input, if input is still available it may be anoth
 471001                            break;
 1002                        }
 01003                    }
 1004
 1005                    // Now, use the source stream's CopyToAsync to push directly to our inflater via this helper stream
 471006                    _deflateStream._stream.CopyTo(this, _arrayPoolBuffer.Length);
 471007                    if (s_useStrictValidation && !_deflateStream._inflater.Finished())
 01008                    {
 01009                        ThrowTruncatedInvalidData();
 01010                    }
 1011
 1012                    // Rewind the stream if decompression has finished and the stream supports seeking
 471013                    if (_deflateStream._inflater.Finished() && !_deflateStream._decompressionFinished && _deflateStream.
 01014                    {
 01015                        _deflateStream.TryRewindStream(_deflateStream._stream);
 01016                        _deflateStream._decompressionFinished = true;
 01017                    }
 471018                }
 1019                finally
 471020                {
 471021                    ArrayPool<byte>.Shared.Return(_arrayPoolBuffer);
 471022                    _arrayPoolBuffer = null!;
 471023                }
 471024            }
 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
 471045            {
 471046                _deflateStream.EnsureNotDisposed();
 1047
 471048                return WriteAsyncCore(buffer, cancellationToken);
 471049            }
 1050
 1051            private async ValueTask WriteAsyncCore(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
 471052            {
 471053                Debug.Assert(_deflateStream._inflater is not null);
 1054
 1055                // Feed the data from base stream into decompression engine.
 471056                _deflateStream._inflater.SetInput(buffer);
 1057
 1058                // While there's more decompressed data available, forward it to the buffer stream.
 941059                while (!_deflateStream._inflater.Finished())
 471060                {
 471061                    int bytesRead = _deflateStream._inflater.Inflate(new Span<byte>(_arrayPoolBuffer));
 471062                    if (bytesRead > 0)
 471063                    {
 471064                        await _destination.WriteAsync(new ReadOnlyMemory<byte>(_arrayPoolBuffer, 0, bytesRead), cancella
 471065                    }
 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                    }
 471071                }
 471072            }
 1073
 1074            public override void Write(byte[] buffer, int offset, int count)
 471075            {
 471076                Debug.Assert(buffer != _arrayPoolBuffer);
 471077                _deflateStream.EnsureNotDisposed();
 1078
 471079                if (count <= 0)
 01080                {
 01081                    return;
 1082                }
 471083                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
 471090                Debug.Assert(_deflateStream._inflater != null);
 1091                // Feed the data from base stream into the decompression engine.
 471092                _deflateStream._inflater.SetInput(buffer, offset, count);
 1093
 1094                // While there's more decompressed data available, forward it to the buffer stream.
 941095                while (!_deflateStream._inflater.Finished())
 471096                {
 471097                    int bytesRead = _deflateStream._inflater.Inflate(new Span<byte>(_arrayPoolBuffer));
 471098                    if (bytesRead > 0)
 471099                    {
 471100                        _destination.Write(_arrayPoolBuffer, 0, bytesRead);
 471101                    }
 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                    }
 471107                }
 471108            }
 1109
 941110            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()
 11821122        {
 11821123            if (_activeAsyncOperation)
 01124            {
 01125                ThrowInvalidBeginCall();
 01126            }
 11821127        }
 1128
 1129        private void AsyncOperationStarting()
 11821130        {
 11821131            if (Interlocked.Exchange(ref _activeAsyncOperation, true))
 01132            {
 01133                ThrowInvalidBeginCall();
 01134            }
 11821135        }
 1136
 1137        private void AsyncOperationCompleting()
 11821138        {
 11821139            Debug.Assert(_activeAsyncOperation);
 11821140            _activeAsyncOperation = false;
 11821141        }
 1142
 1143        private static void ThrowInvalidBeginCall() =>
 01144            throw new InvalidOperationException(SR.InvalidBeginCall);
 1145
 11146        private static readonly bool s_useStrictValidation =
 11147            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()