/// <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); }