C# Class NetWrok.HTTP.Zlib.ZlibStream

Represents a Zlib stream for compression or decompression.

Data can be compressed or decompressed, and either of those can be through reading or writing. For more information on the Deflate algorithm, see IETF RFC 1951, "DEFLATE Compressed Data Format Specification version 1.3."

This class is similar to DeflateStream, except that it adds the RFC1950 header bytes to a compressed stream when compressing, or expects the RFC1950 header bytes when decompressing. It is also similar to the GZipStream.

Inheritance: System.IO.Stream
Show file Open project: simonwittber/netwrok-client

Public Methods

Method Description
Close ( ) : void

Close the stream.

This may or may not close the captive stream. See the ctor's with leaveOpen parameters for more information.

Flush ( ) : void

Flush the stream.

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

Read data from the stream.

If you wish to use the ZlibStream to compress data while reading, you can create a ZlibStream with CompressionMode.Compress, providing an uncompressed data stream. Then call Read() on that ZlibStream, and the data read will be compressed. If you wish to use the ZlibStream to decompress data while reading, you can create a ZlibStream with CompressionMode.Decompress, providing a readable compressed data stream. Then call Read() on that ZlibStream, and the data read will be decompressed.

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

Seek ( long offset, System 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 ZlibStream to compress data while writing, you can create a ZlibStream with CompressionMode.Compress, and a writable output stream. Then call Write() on that ZlibStream, 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 ZlibStream to decompress data while writing, you can create a ZlibStream 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 ZlibStream can be used for Read() or Write(), but not both.

ZlibStream ( System stream, CompressionMode mode ) : System

Create a ZlibStream using the specified CompressionMode.

The ZlibStream will use the default compression level.

See the documentation for the DeflateStream constructors for example code.

ZlibStream ( System stream, CompressionMode mode, CompressionLevel level ) : System

Create a ZlibStream using the specified CompressionMode and the specified CompressionLevel.

See the documentation for the DeflateStream constructors for example code.

ZlibStream ( System stream, CompressionMode mode, CompressionLevel level, bool leaveOpen ) : System

Create a ZlibStream 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, after Close() 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 compression. Specify true for the leaveOpen parameter to leave the stream open.

ZlibStream ( System stream, CompressionMode mode, bool leaveOpen ) : System

Create a ZlibStream 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, after Close() 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 compression. Specify true for the leaveOpen parameter to leave the stream open.

The ZlibStream will use the default compression level.

See the documentation for the DeflateStream constructors for example code.

Method Details

Close() public method

Close the stream.
This may or may not close the captive stream. See the ctor's with leaveOpen parameters for more information.
public Close ( ) : void
return void

Flush() public method

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

Read() public method

Read data from the stream.

If you wish to use the ZlibStream to compress data while reading, you can create a ZlibStream with CompressionMode.Compress, providing an uncompressed data stream. Then call Read() on that ZlibStream, and the data read will be compressed. If you wish to use the ZlibStream to decompress data while reading, you can create a ZlibStream with CompressionMode.Decompress, providing a readable compressed data stream. Then call Read() on that ZlibStream, and the data read will be decompressed.

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

public Read ( byte buffer, int offset, int count ) : int
buffer byte The buffer into which the read 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, System origin ) : long
offset long
origin System
return long

SetLength() public method

Calling this method always throws a NotImplementedException.
public SetLength ( long value ) : void
value long
return void

Write() public method

Write data to the stream.

If you wish to use the ZlibStream to compress data while writing, you can create a ZlibStream with CompressionMode.Compress, and a writable output stream. Then call Write() on that ZlibStream, 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 ZlibStream to decompress data while writing, you can create a ZlibStream 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 ZlibStream 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

ZlibStream() public method

Create a ZlibStream using the specified CompressionMode.

The ZlibStream will use the default compression level.

See the documentation for the DeflateStream constructors for example code.

public ZlibStream ( System stream, CompressionMode mode ) : System
stream System The stream which will be read or written.
mode CompressionMode Indicates whether the ZlibStream will compress or decompress.
return System

ZlibStream() public method

Create a ZlibStream using the specified CompressionMode and the specified CompressionLevel.
See the documentation for the DeflateStream constructors for example code.
public ZlibStream ( System stream, CompressionMode mode, CompressionLevel level ) : System
stream System The stream to be read or written while deflating or inflating.
mode CompressionMode Indicates whether the ZlibStream will compress or decompress.
level CompressionLevel A tuning knob to trade speed for effectiveness.
return System

ZlibStream() public method

Create a ZlibStream 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, after Close() 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 compression. Specify true for the leaveOpen parameter to leave the stream open.

public ZlibStream ( System stream, CompressionMode mode, CompressionLevel level, bool leaveOpen ) : System
stream System The stream which will be read or written.
mode CompressionMode Indicates whether the ZlibStream 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

ZlibStream() public method

Create a ZlibStream 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, after Close() 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 compression. Specify true for the leaveOpen parameter to leave the stream open.

The ZlibStream will use the default compression level.

See the documentation for the DeflateStream constructors for example code.

public ZlibStream ( System stream, CompressionMode mode, bool leaveOpen ) : System
stream System 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 ZlibStream will compress or decompress.
leaveOpen bool true if the application would like the stream to remain open after inflation/deflation.
return System