Exemple #1
0
        // A specific constructor to allow decompression of Deflate64
        internal Deflate64Stream(Stream stream, long uncompressedSize = -1)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (!stream.CanRead)
            {
                throw new ArgumentException("NotSupported_UnreadableStream", nameof(stream));
            }

            _inflater = new InflaterManaged(null, true, uncompressedSize);

            _stream = stream;
            _buffer = new byte[DefaultBufferSize];
        }
Exemple #2
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                PurgeBuffers(disposing);
            }
            finally
            {
                // Close the underlying stream even if PurgeBuffers threw.
                // Stream.Close() may throw here (may or may not be due to the same error).
                // In this case, we still need to clean up internal resources, hence the inner finally blocks.
                try
                {
                    if (disposing && _stream != null)
                    {
                        _stream.Dispose();
                    }
                }
                finally
                {
                    _stream = null;

                    try
                    {
                        if (_inflater != null)
                        {
                            _inflater.Dispose();
                        }
                    }
                    finally
                    {
                        _inflater = null;
                        base.Dispose(disposing);
                    }
                }
            }
        }