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?.Dispose(); } } finally { _stream = null; try { _inflater?.Dispose(); } finally { _inflater = null; base.Dispose(disposing); } } } }
/// <summary> /// Sets up this DeflateManagedStream to be used for Inflation/Decompression /// </summary> private void InitializeInflater(Stream stream, ZipCompressionMethod method = ZipCompressionMethod.Deflate) { Debug.Assert(stream != null); Debug.Assert(method == ZipCompressionMethod.Deflate || method == ZipCompressionMethod.Deflate64); if (!stream.CanRead) { throw new ArgumentException("Deflate64: input stream is not readable", nameof(stream)); } _inflater = new InflaterManaged(method == ZipCompressionMethod.Deflate64); _stream = stream; _mode = CompressionMode.Decompress; _buffer = new byte[DEFAULT_BUFFER_SIZE]; }
/// <summary> /// Sets up this DeflateManagedStream to be used for Inflation/Decompression /// </summary> internal void InitializeInflater(Stream stream, bool leaveOpen, ZipCompressionMethod method = ZipCompressionMethod.Deflate) { Debug.Assert(stream != null); Debug.Assert(method == ZipCompressionMethod.Deflate || method == ZipCompressionMethod.Deflate64); if (!stream.CanRead) { throw new ArgumentException("Deflate64: input stream is not readable", nameof(stream)); } _inflater = new InflaterManaged(method == ZipCompressionMethod.Deflate64); _stream = stream; _mode = CompressionMode.Decompress; _leaveOpen = leaveOpen; _buffer = new byte[DefaultBufferSize]; }