/// <summary> /// Write data to the stream. /// </summary> /// <remarks> /// /// <para> /// If you wish to use the <c>DeflateStream</c> to compress data while /// writing, you can create a <c>DeflateStream</c> with /// <c>CompressionMode.Compress</c>, and a writable output stream. Then call /// <c>Write()</c> on that <c>DeflateStream</c>, providing uncompressed data /// as input. The data sent to the output stream will be the compressed form /// of the data written. If you wish to use the <c>DeflateStream</c> to /// decompress data while writing, you can create a <c>DeflateStream</c> with /// <c>CompressionMode.Decompress</c>, and a writable output stream. Then /// call <c>Write()</c> on that stream, providing previously compressed /// data. The data sent to the output stream will be the decompressed form of /// the data written. /// </para> /// /// <para> /// A <c>DeflateStream</c> can be used for <c>Read()</c> or <c>Write()</c>, /// but not both. /// </para> /// /// </remarks> /// /// <param name="buffer">The buffer holding data to write to the stream.</param> /// <param name="offset">the offset within that data array to find the first byte to write.</param> /// <param name="count">the number of bytes to write.</param> public override void Write(byte[] buffer, int offset, int count) { if (_disposed) { throw new ObjectDisposedException("DeflateStream"); } _baseStream.Write(buffer, offset, count); }
/// <summary> /// Write data to the stream. /// </summary> /// /// <remarks> /// <para> /// If you wish to use the <c>GZipStream</c> to compress data while writing, /// you can create a <c>GZipStream</c> with <c>CompressionMode.Compress</c>, and a /// writable output stream. Then call <c>Write()</c> on that <c>GZipStream</c>, /// providing uncompressed data as input. The data sent to the output stream /// will be the compressed form of the data written. /// </para> /// /// <para> /// A <c>GZipStream</c> can be used for <c>Read()</c> or <c>Write()</c>, but not /// both. Writing implies compression. Reading implies decompression. /// </para> /// /// </remarks> /// <param name="buffer">The buffer holding data to write to the stream.</param> /// <param name="offset">the offset within that data array to find the first byte to write.</param> /// <param name="count">the number of bytes to write.</param> public override void Write(byte[] buffer, int offset, int count) { if (disposed) { throw new ObjectDisposedException("GZipStream"); } if (BaseStream._streamMode == ZlibBaseStream.StreamMode.Undefined) { //Console.WriteLine("GZipStream: First write"); if (BaseStream._wantCompress) { // first write in compression, therefore, emit the GZIP header headerByteCount = EmitHeader(); } else { throw new InvalidOperationException(); } } BaseStream.Write(buffer, offset, count); }