< 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
44%
Covered lines: 301
Uncovered lines: 378
Coverable lines: 679
Total lines: 1149
Line coverage: 44.3%
Branch coverage
40%
Covered branches: 106
Total branches: 259
Branch coverage: 40.9%
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%11100%
WriteByte(...)0%220%
Write(...)0%220%
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(...)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()50%2250%
AsyncOperationStarting()50%2250%
AsyncOperationCompleting()100%11100%
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
 129827        internal DeflateStream(Stream stream, CompressionMode mode, long uncompressedSize) : this(stream, mode, leaveOpe
 129828        {
 129829        }
 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
 129245        public DeflateStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen) : this(stream, compressio
 129246        {
 129247        }
 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>
 129878        internal DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen, int windowBits, long uncompressedSiz
 129879        {
 129880            ArgumentNullException.ThrowIfNull(stream);
 81
 129882            switch (mode)
 83            {
 84                case CompressionMode.Decompress:
 129885                    if (!stream.CanRead)
 086                        throw new ArgumentException(SR.NotSupported_UnreadableStream, nameof(stream));
 87
 129888                    _inflater = Inflater.CreateInflater(windowBits, uncompressedSize);
 129889                    _stream = stream;
 129890                    _mode = CompressionMode.Decompress;
 129891                    _leaveOpen = leaveOpen;
 129892                    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            }
 1298101        }
 102
 103        /// <summary>
 104        /// Internal constructor to specify the compressionLevel as well as the windowBits
 105        /// </summary>
 1292106        internal DeflateStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen, int windowBits)
 1292107        {
 1292108            ArgumentNullException.ThrowIfNull(stream);
 109
 1292110            InitializeDeflater(stream, GetZLibNativeCompressionLevel(compressionLevel), CompressionStrategy.DefaultStrat
 1292111        }
 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
 1292118        {
 1292119            Debug.Assert(stream != null);
 1292120            if (!stream.CanWrite)
 0121                throw new ArgumentException(SR.NotSupported_UnwritableStream, nameof(stream));
 122
 1292123            _deflater = Deflater.CreateDeflater(compressionLevel, strategy, windowBits, GetMemLevel(compressionLevel));
 124
 1292125            _stream = stream;
 1292126            _mode = CompressionMode.Compress;
 1292127            _leaveOpen = leaveOpen;
 1292128            InitializeBuffer();
 1292129        }
 130
 131        private static ZLibNative.CompressionLevel GetZLibNativeCompressionLevel(CompressionLevel compressionLevel) =>
 1292132            compressionLevel switch
 1292133            {
 1292134                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)),
 1292139            };
 140
 141        private static int GetMemLevel(ZLibNative.CompressionLevel level) =>
 1292142            level == ZLibNative.CompressionLevel.NoCompression ?
 1292143                Deflate_NoCompressionMemLevel :
 1292144                Deflate_DefaultMemLevel;
 145
 146        [MemberNotNull(nameof(_buffer))]
 147        private void InitializeBuffer()
 2590148        {
 2590149            Debug.Assert(_buffer == null);
 2590150            _buffer = ArrayPool<byte>.Shared.Rent(DefaultBufferSize);
 2590151        }
 152
 153        [MemberNotNull(nameof(_buffer))]
 154        private void EnsureBufferInitialized()
 2590155        {
 2590156            if (_buffer == null)
 1298157            {
 1298158                InitializeBuffer();
 1298159            }
 2590160        }
 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
 1298174            {
 1298175                if (_stream == null)
 0176                {
 0177                    return false;
 178                }
 179
 1298180                return (_mode == CompressionMode.Decompress && _stream.CanRead);
 1298181            }
 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
 1298197        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)
 1295291        {
 1295292            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
 1295300            {
 1295301                return ReadCore(buffer);
 302            }
 1292303        }
 304
 305        internal int ReadCore(Span<byte> buffer)
 1295306        {
 1295307            EnsureDecompressionMode();
 1295308            EnsureNotDisposed();
 1295309            EnsureBufferInitialized();
 1295310            Debug.Assert(_inflater != null);
 311
 312            int bytesRead;
 1944313            while (true)
 1944314            {
 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.
 1944317                bytesRead = _inflater.Inflate(buffer);
 1941318                if (bytesRead != 0 || InflatorIsFinished)
 1292319                {
 1292320                    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.
 649325                if (_inflater.NeedsInput())
 649326                {
 649327                    int n = _stream.Read(_buffer, 0, _buffer.Length);
 649328                    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                    }
 649341                    else if (n > _buffer.Length)
 0342                    {
 0343                        ThrowGenericInvalidData();
 0344                    }
 345                    else
 649346                    {
 649347                        _inflater.SetInput(_buffer, 0, n);
 649348                    }
 649349                }
 350
 649351                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                }
 649362            }
 363
 364            // When decompression finishes, rewind the stream to the exact end of compressed data
 1292365            if (bytesRead == 0 && InflatorIsFinished && !_decompressionFinished && _stream.CanSeek)
 0366            {
 0367                TryRewindStream(_stream);
 0368                _decompressionFinished = true;
 0369            }
 370
 1292371            return bytesRead;
 1292372        }
 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
 3882379            _inflater!.Finished() &&
 3882380            (!_inflater.IsGzipStream() || !_inflater.NeedsInput());
 381
 382        private void EnsureNotDisposed()
 3882383        {
 3882384            ObjectDisposedException.ThrowIf(_stream is null, this);
 3882385        }
 386
 387        private void EnsureDecompressionMode()
 2590388        {
 2590389            if (_mode != CompressionMode.Decompress)
 0390                ThrowCannotReadFromDeflateStreamException();
 391
 392            static void ThrowCannotReadFromDeflateStreamException() =>
 0393                throw new InvalidOperationException(SR.CannotReadFromDeflateStream);
 2590394        }
 395
 396        private void EnsureCompressionMode()
 1292397        {
 1292398            if (_mode != CompressionMode.Compress)
 0399                ThrowCannotWriteToDeflateStreamException();
 400
 401            static void ThrowCannotWriteToDeflateStreamException() =>
 0402                throw new InvalidOperationException(SR.CannotWriteToDeflateStream);
 1292403        }
 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)
 1295430        {
 1295431            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
 1295438            {
 1295439                return ReadAsyncMemory(buffer, cancellationToken);
 440            }
 1295441        }
 442
 443        internal ValueTask<int> ReadAsyncMemory(Memory<byte> buffer, CancellationToken cancellationToken)
 1295444        {
 1295445            EnsureDecompressionMode();
 1295446            EnsureNoActiveAsyncOperation();
 1295447            EnsureNotDisposed();
 448
 1295449            if (cancellationToken.IsCancellationRequested)
 0450            {
 0451                return ValueTask.FromCanceled<int>(cancellationToken);
 452            }
 453
 1295454            EnsureBufferInitialized();
 1295455            Debug.Assert(_inflater != null);
 456
 1295457            return Core(buffer, cancellationToken);
 458
 459            async ValueTask<int> Core(Memory<byte> buffer, CancellationToken cancellationToken)
 1295460            {
 1295461                AsyncOperationStarting();
 462                try
 1295463                {
 464                    int bytesRead;
 1944465                    while (true)
 1944466                    {
 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.
 1944469                        bytesRead = _inflater.Inflate(buffer.Span);
 1941470                        if (bytesRead != 0 || InflatorIsFinished)
 1292471                        {
 1292472                            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.
 649477                        if (_inflater.NeedsInput())
 649478                        {
 649479                            int n = await _stream.ReadAsync(new Memory<byte>(_buffer, 0, _buffer.Length), cancellationTo
 649480                            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                            }
 649493                            else if (n > _buffer.Length)
 0494                            {
 0495                                ThrowGenericInvalidData();
 0496                            }
 497                            else
 649498                            {
 649499                                _inflater.SetInput(_buffer, 0, n);
 649500                            }
 649501                        }
 502
 649503                        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                        }
 649513                    }
 514
 515                    // When decompression finishes, rewind the stream to the exact end of compressed data
 1292516                    if (bytesRead == 0 && InflatorIsFinished && !_decompressionFinished && _stream.CanSeek)
 0517                    {
 0518                        TryRewindStream(_stream);
 0519                        _decompressionFinished = true;
 0520                    }
 521
 1292522                    return bytesRead;
 523                }
 524                finally
 1295525                {
 1295526                    AsyncOperationCompleting();
 1295527                }
 1292528            }
 1295529        }
 530
 531        public override void Write(byte[] buffer, int offset, int count)
 646532        {
 646533            ValidateBufferArguments(buffer, offset, count);
 646534            WriteCore(new ReadOnlySpan<byte>(buffer, offset, count));
 646535        }
 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)
 646568        {
 646569            EnsureCompressionMode();
 646570            EnsureNotDisposed();
 571
 646572            if (buffer.IsEmpty)
 0573            {
 0574                return;
 575            }
 576
 577            // Write compressed the bytes we already passed to the deflater:
 646578            Debug.Assert(_deflater != null);
 646579            WriteDeflaterOutput();
 580
 581            unsafe
 646582            {
 583                // Pass new bytes through deflater and write them too:
 646584                fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer))
 646585                {
 646586                    _deflater.SetInput(bufferPtr, buffer.Length);
 646587                    WriteDeflaterOutput();
 646588                }
 646589            }
 646590        }
 591
 592        private void WriteDeflaterOutput()
 1938593        {
 1938594            Debug.Assert(_deflater != null && _buffer != null);
 2584595            while (!_deflater.NeedsInput())
 646596            {
 646597                int compressedBytes = _deflater.GetDeflateOutput(_buffer);
 646598                if (compressedBytes > 0)
 0599                {
 0600                    _stream.Write(_buffer, 0, compressedBytes);
 0601                }
 646602            }
 1938603        }
 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)
 1295631        {
 1295632            if (!disposing)
 0633                return;
 634
 1295635            if (_stream == null)
 0636                return;
 637
 1295638            if (_mode != CompressionMode.Compress)
 649639                return;
 640
 646641            Debug.Assert(_deflater != null && _buffer != null);
 642            // Compress any bytes left
 646643            WriteDeflaterOutput();
 644
 645            // Pull out any bytes left inside deflater:
 646            bool finished;
 647            do
 646648            {
 649                int compressedBytes;
 646650                finished = _deflater.Finish(_buffer, out compressedBytes);
 651
 646652                if (compressedBytes > 0)
 646653                    _stream.Write(_buffer, 0, compressedBytes);
 1292654            } while (!finished);
 1295655        }
 656
 657        private async ValueTask PurgeBuffersAsync()
 1295658        {
 659            // Same logic as PurgeBuffers, except with async counterparts.
 660
 1295661            if (_stream == null)
 0662                return;
 663
 1295664            if (_mode != CompressionMode.Compress)
 649665                return;
 666
 646667            Debug.Assert(_deflater != null && _buffer != null);
 668            // Compress any bytes left
 646669            await WriteDeflaterOutputAsync(default).ConfigureAwait(false);
 670
 671            // Pull out any bytes left inside deflater:
 672            bool finished;
 673            do
 646674            {
 675                int compressedBytes;
 646676                finished = _deflater.Finish(_buffer, out compressedBytes);
 677
 646678                if (compressedBytes > 0)
 646679                    await _stream.WriteAsync(new ReadOnlyMemory<byte>(_buffer, 0, compressedBytes)).ConfigureAwait(false
 1292680            } while (!finished);
 1295681        }
 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)
 1295711        {
 712            try
 1295713            {
 1295714                PurgeBuffers(disposing);
 1295715            }
 716            finally
 1295717            {
 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
 1295722                {
 1295723                    if (disposing && !_leaveOpen)
 649724                    {
 649725                        _stream?.Dispose();
 649726                    }
 1295727                }
 728                finally
 1295729                {
 1295730                    _stream = null!;
 731
 732                    try
 1295733                    {
 1295734                        _deflater?.Dispose();
 1295735                        _inflater?.Dispose();
 1295736                    }
 737                    finally
 1295738                    {
 1295739                        _deflater = null;
 1295740                        _inflater = null;
 741
 1295742                        byte[]? buffer = _buffer;
 1295743                        if (buffer != null)
 1295744                        {
 1295745                            _buffer = null;
 1295746                            if (!_activeAsyncOperation)
 1295747                            {
 1295748                                ArrayPool<byte>.Shared.Return(buffer);
 1295749                            }
 1295750                        }
 751
 1295752                        base.Dispose(disposing);
 1295753                    }
 1295754                }
 1295755            }
 1295756        }
 757
 758        public override ValueTask DisposeAsync()
 1295759        {
 1295760            return GetType() == typeof(DeflateStream) ?
 1295761                Core() :
 1295762                base.DisposeAsync();
 763
 764            async ValueTask Core()
 1295765            {
 766                // Same logic as Dispose(true), except with async counterparts.
 767                try
 1295768                {
 1295769                    await PurgeBuffersAsync().ConfigureAwait(false);
 1295770                }
 771                finally
 1295772                {
 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.
 1295776                    Stream stream = _stream;
 1295777                    _stream = null!;
 778                    try
 1295779                    {
 1295780                        if (!_leaveOpen && stream != null)
 649781                        {
 649782                            await stream.DisposeAsync().ConfigureAwait(false);
 649783                        }
 1295784                    }
 785                    finally
 1295786                    {
 787                        try
 1295788                        {
 1295789                            _deflater?.Dispose();
 1295790                            _inflater?.Dispose();
 1295791                        }
 792                        finally
 1295793                        {
 1295794                            _deflater = null;
 1295795                            _inflater = null;
 796
 1295797                            byte[]? buffer = _buffer;
 1295798                            if (buffer != null)
 1295799                            {
 1295800                                _buffer = null;
 1295801                                if (!_activeAsyncOperation)
 1295802                                {
 1295803                                    ArrayPool<byte>.Shared.Return(buffer);
 1295804                                }
 1295805                            }
 1295806                        }
 1295807                    }
 1295808                }
 809            }
 2590810        }
 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)
 646829        {
 646830            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
 646837            {
 646838                return WriteAsyncMemory(buffer, cancellationToken);
 839            }
 646840        }
 841
 842        internal ValueTask WriteAsyncMemory(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
 646843        {
 646844            EnsureCompressionMode();
 646845            EnsureNoActiveAsyncOperation();
 646846            EnsureNotDisposed();
 847
 646848            return
 646849                cancellationToken.IsCancellationRequested ? ValueTask.FromCanceled(cancellationToken) :
 646850                buffer.IsEmpty ? default :
 646851                Core(buffer, cancellationToken);
 852
 853            async ValueTask Core(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
 646854            {
 646855                AsyncOperationStarting();
 856                try
 646857                {
 646858                    await WriteDeflaterOutputAsync(cancellationToken).ConfigureAwait(false);
 859
 860                    // Pass new bytes through deflater
 646861                    Debug.Assert(_deflater != null);
 646862                    _deflater.SetInput(buffer);
 863
 646864                    await WriteDeflaterOutputAsync(cancellationToken).ConfigureAwait(false);
 646865                }
 866                finally
 646867                {
 646868                    AsyncOperationCompleting();
 646869                }
 646870            }
 646871        }
 872
 873        /// <summary>
 874        /// Writes the bytes that have already been deflated
 875        /// </summary>
 876        private async ValueTask WriteDeflaterOutputAsync(CancellationToken cancellationToken)
 1938877        {
 1938878            Debug.Assert(_deflater != null && _buffer != null);
 2584879            while (!_deflater.NeedsInput())
 646880            {
 646881                int compressedBytes = _deflater.GetDeflateOutput(_buffer);
 646882                if (compressedBytes > 0)
 0883                {
 0884                    await _stream.WriteAsync(new ReadOnlyMemory<byte>(_buffer, 0, compressedBytes), cancellationToken).C
 0885                }
 646886            }
 1938887        }
 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()
 19411122        {
 19411123            if (_activeAsyncOperation)
 01124            {
 01125                ThrowInvalidBeginCall();
 01126            }
 19411127        }
 1128
 1129        private void AsyncOperationStarting()
 19411130        {
 19411131            if (Interlocked.Exchange(ref _activeAsyncOperation, true))
 01132            {
 01133                ThrowInvalidBeginCall();
 01134            }
 19411135        }
 1136
 1137        private void AsyncOperationCompleting()
 19411138        {
 19411139            Debug.Assert(_activeAsyncOperation);
 19411140            _activeAsyncOperation = false;
 19411141        }
 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()