public DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen) { if (stream == null) { throw new ArgumentNullException("stream"); } if (CompressionMode.Compress != mode && mode != CompressionMode.Decompress) { throw new ArgumentException(SR.GetString("Argument out of range"), "mode"); } this._stream = stream; this._mode = mode; this._leaveOpen = leaveOpen; CompressionMode mode2 = this._mode; if (mode2 != CompressionMode.Decompress) { if (mode2 == CompressionMode.Compress) { if (!this._stream.CanWrite) { throw new ArgumentException(SR.GetString("Not a writeable stream"), "stream"); } this.deflater = DeflateStream.CreateDeflater(); this.m_AsyncWriterDelegate = new DeflateStream.AsyncWriteDelegate(this.InternalWrite); this.m_CallBack = new AsyncCallback(this.WriteCallback); } } else { if (!this._stream.CanRead) { throw new ArgumentException(SR.GetString("Not a readable stream"), "stream"); } this.inflater = new Inflater(); this.m_CallBack = new AsyncCallback(this.ReadCallback); } this.buffer = new byte[8192]; }
public DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (CompressionMode.Compress != mode && (uint)mode > 0U) { throw new ArgumentException(SR.GetString("Argument out of range"), nameof(mode)); } this._stream = stream; this._mode = mode; this._leaveOpen = leaveOpen; switch (this._mode) { case CompressionMode.Decompress: if (!this._stream.CanRead) { throw new ArgumentException(SR.GetString("Not a readable stream"), nameof(stream)); } this.inflater = new Inflater(); this.m_CallBack = new AsyncCallback(this.ReadCallback); break; case CompressionMode.Compress: if (!this._stream.CanWrite) { throw new ArgumentException(SR.GetString("Not a writeable stream"), nameof(stream)); } this.deflater = DeflateStream.CreateDeflater(); this.m_AsyncWriterDelegate = new DeflateStream.AsyncWriteDelegate(this.InternalWrite); this.m_CallBack = new AsyncCallback(this.WriteCallback); break; } this.buffer = new byte[8192]; }