NetWrok.HTTP.Zlib.GZipStream.Write C# (CSharp) Method

Write() public method

Write data to the stream.

If you wish to use the GZipStream to compress data while writing, you can create a GZipStream with CompressionMode.Compress, and a writable output stream. Then call Write() on that GZipStream, 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 DeflateStream to decompress data while writing, you can create a GZipStream with CompressionMode.Decompress, and a writable output stream. Then call Write() on that stream, providing previously compressed data. The data sent to the output stream will be the decompressed form of the data written.

A GZipStream can be used for Read() or Write(), but not both.

public Write ( byte buffer, int offset, int count ) : void
buffer byte The buffer holding data to write to the stream.
offset int the offset within that data array to find the first byte to write.
count int the number of bytes to write.
return void
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (_baseStream._streamMode == HTTP.Zlib.ZlibBaseStream.StreamMode.Undefined)
            {
                //Console.WriteLine("GZipStream: First write");
                if (_baseStream._wantCompress)
                {
                    // first write in compression, therefore, emit the GZIP header
                    EmitHeader();
                }
                else
                {
                    // first write in decompression, therefore, pop off GZIP header
                    int n = SlurpHeader(buffer, offset);
                    offset += n;
                    count -= n;
                }
            }

            _baseStream.Write(buffer, offset, count);
        }