/// <summary> /// Sets up this DeflateManagedStream to be used for Deflation/Compression /// </summary> internal void InitializeDeflater(Stream stream, bool leaveOpen, CompressionLevel compressionLevel) { Debug.Assert(stream != null); if (!stream.CanWrite) { throw new ArgumentException(SR.NotSupported_UnwritableStream, nameof(stream)); } _deflater = new DeflaterManaged(); _stream = stream; _mode = CompressionMode.Compress; _leaveOpen = leaveOpen; _buffer = new byte[DefaultBufferSize]; }
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 && !_leaveOpen && _stream != null) { _stream.Dispose(); } } finally { _stream = null; try { if (_deflater != null) { _deflater.Dispose(); } if (_inflater != null) { _inflater.Dispose(); } } finally { _deflater = null; _inflater = null; base.Dispose(disposing); } } } }
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 && !_leaveOpen && _stream != null) _stream.Dispose(); } finally { _stream = null; try { if (_deflater != null) _deflater.Dispose(); if (_inflater != null) _inflater.Dispose(); } finally { _deflater = null; _inflater = null; base.Dispose(disposing); } } } }
/// <summary> /// Sets up this DeflateManagedStream to be used for Deflation/Compression /// </summary> internal void InitializeDeflater(Stream stream, bool leaveOpen, CompressionLevel compressionLevel) { Debug.Assert(stream != null); if (!stream.CanWrite) throw new ArgumentException(SR.NotSupported_UnwritableStream, nameof(stream)); _deflater = new DeflaterManaged(); _stream = stream; _mode = CompressionMode.Compress; _leaveOpen = leaveOpen; _buffer = new byte[DefaultBufferSize]; }