C# Class Zlib.GZipStream

A class for compressing and decompressing GZIP streams.
Inheritance: Stream
Show file Open project: robertbaker/SevenUpdate

Public Methods

Method Description
Flush ( ) : void

Flush the stream.

GZipStream ( Stream stream, CompressionMode mode, CompressionLevel level = CompressionLevel.Default, bool leaveOpen = false ) : System

Create a GZipStream using the specified CompressionMode and the specified CompressionLevel, and explicitly specify whether the stream should be left open after Deflation or Inflation.

This constructor allows the application to request that the captive stream remain open after the deflation or inflation occurs. By default, afterClose() is called on the stream, the captive stream is also closed. In some cases this is not desired, for example if the stream is a memory stream that will be re-read after compressed data has been written to it. Specify true for the leaveOpen parameter to leave the stream open.

As noted in the class documentation, the CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. AGZipStream with CompressionMode.Compress works only throughWrite(). A GZipStream with CompressionMode.Decompress works only through Read().

GZipStream ( Stream stream, CompressionMode mode, bool leaveOpen ) : System

Create a GZipStream using the specified CompressionMode, and explicitly specify whether the stream should be left open after Deflation or Inflation.

This constructor allows the application to request that the captive stream remain open after the deflation or inflation occurs. By default, afterClose() is called on the stream, the captive stream is also closed. In some cases this is not desired, for example if the stream is a memory stream that will be re-read after compressed data has been written to it. Specify true for the leaveOpen parameter to leave the stream open.

The CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. A GZipStream withCompressionMode.Compress works only through Write(). A GZipStream with CompressionMode.Decompress works only through Read().

See the other overloads of this constructor for example code.

Read ( byte buffer, int offset, int count ) : int

Read and decompress data from the source stream.

With a GZipStream, decompression is done through reading.

Seek ( long offset, SeekOrigin origin ) : long

Calling this method always throws a NotImplementedException.

SetLength ( long value ) : void

Calling this method always throws a NotImplementedException.

Write ( byte buffer, int offset, int count ) : void

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.

A GZipStream can be used for Read() or Write(), but not both. Writing implies compression. Reading implies decompression.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Dispose the stream.

This may or may not result in a Close() call on the captive stream. See the doc on constructors that take a leaveOpen parameter for more information.

Private Methods

Method Description
EmitHeader ( ) : int

Method Details

Dispose() protected method

Dispose the stream.
This may or may not result in a Close() call on the captive stream. See the doc on constructors that take a leaveOpen parameter for more information.
protected Dispose ( bool disposing ) : void
disposing bool
return void

Flush() public method

Flush the stream.
public Flush ( ) : void
return void

GZipStream() public method

Create a GZipStream using the specified CompressionMode and the specified CompressionLevel, and explicitly specify whether the stream should be left open after Deflation or Inflation.

This constructor allows the application to request that the captive stream remain open after the deflation or inflation occurs. By default, afterClose() is called on the stream, the captive stream is also closed. In some cases this is not desired, for example if the stream is a memory stream that will be re-read after compressed data has been written to it. Specify true for the leaveOpen parameter to leave the stream open.

As noted in the class documentation, the CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. AGZipStream with CompressionMode.Compress works only throughWrite(). A GZipStream with CompressionMode.Decompress works only through Read().

public GZipStream ( Stream stream, CompressionMode mode, CompressionLevel level = CompressionLevel.Default, bool leaveOpen = false ) : System
stream Stream The stream which will be read or written.
mode CompressionMode Indicates whether the GZipStream will compress or decompress.
level CompressionLevel A tuning knob to trade speed for effectiveness.
leaveOpen bool true if the application would like the stream to remain open after inflation/deflation.
return System

GZipStream() public method

Create a GZipStream using the specified CompressionMode, and explicitly specify whether the stream should be left open after Deflation or Inflation.

This constructor allows the application to request that the captive stream remain open after the deflation or inflation occurs. By default, afterClose() is called on the stream, the captive stream is also closed. In some cases this is not desired, for example if the stream is a memory stream that will be re-read after compressed data has been written to it. Specify true for the leaveOpen parameter to leave the stream open.

The CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. A GZipStream withCompressionMode.Compress works only through Write(). A GZipStream with CompressionMode.Decompress works only through Read().

See the other overloads of this constructor for example code.

public GZipStream ( Stream stream, CompressionMode mode, bool leaveOpen ) : System
stream Stream The stream which will be read or written. This is called the "captive" stream in other places in this documentation.
mode CompressionMode Indicates whether the GZipStream will compress or decompress.
leaveOpen bool true if the application would like the base stream to remain open after inflation/deflation.
return System

Read() public method

Read and decompress data from the source stream.
With a GZipStream, decompression is done through reading.
public Read ( byte buffer, int offset, int count ) : int
buffer byte The buffer into which the decompressed data should be placed.
offset int the offset within that data array to put the first byte read.
count int the number of bytes to read.
return int

Seek() public method

Calling this method always throws a NotImplementedException.
public Seek ( long offset, SeekOrigin origin ) : long
offset long This parameter is not used
origin SeekOrigin This parameter is not used
return long

SetLength() public method

Calling this method always throws a NotImplementedException.
public SetLength ( long value ) : void
value long This parameter is not used
return void

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.

A GZipStream can be used for Read() or Write(), but not both. Writing implies compression. Reading implies decompression.

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