C# Class NetWrok.HTTP.Zlib.ZlibCodec

Encoder and Decoder for ZLIB (IETF RFC1950 and RFC1951).
This class compresses and decompresses data according to the Deflate algorithm documented in RFC1950 and RFC1951.
Show file Open project: simonwittber/netwrok-client Class Usage Examples

Public Properties

Property Type Description
AvailableBytesIn int
AvailableBytesOut int
InputBuffer byte[]
Message System.String
NextIn int
NextOut int
OutputBuffer byte[]
TotalBytesIn long
TotalBytesOut long

Public Methods

Method Description
Deflate ( int flush ) : int

Deflate one batch of data.

You must have set InputBuffer and OutputBuffer before calling this method.

EndDeflate ( ) : int

End a deflation session.

Call this after making a series of one or more calls to Deflate(). All buffers are flushed.

EndInflate ( ) : int

Ends an inflation session.

Call this after successively calling Inflate(). This will cause all buffers to be flushed. After calling this you cannot call Inflate() without a intervening call to one of the InitializeInflate() overloads.

Free ( ) : void
Inflate ( int f ) : int

Inflate the data in the InputBuffer, placing the result in the OutputBuffer.

You must have set InputBuffer and OutputBuffer, NextIn and NextOut, and AvailableBytesIn and AvailableBytesOut before calling this method.

InitializeDeflate ( ) : int

Initialize the ZlibCodec for deflation operation.

The codec will use the MAX window bits and the default level of compression.

InitializeDeflate ( CompressionLevel level ) : int

Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel.

The codec will use the MAX window bits and the specified CompressionLevel.

InitializeDeflate ( CompressionLevel level, bool wantRfc1950Header ) : int

Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel, and the explicit flag governing whether to emit an RFC1950 header byte pair.

The codec will use the MAX window bits and the specified CompressionLevel.

InitializeDeflate ( CompressionLevel level, int bits ) : int

Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel, and the specified number of window bits.

The codec will use the specified number of window bits and the specified CompressionLevel.

InitializeDeflate ( CompressionLevel level, int bits, bool wantRfc1950Header ) : int

Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel, the specified number of window bits, and the explicit flag governing whether to emit an RFC1950 header byte pair.

InitializeInflate ( ) : int

Initialize the inflation state.

It is not necessary to call this before using the ZlibCodec to inflate data; It is implicitly called when you call the constructor.

InitializeInflate ( bool expectRfc1950Header ) : int

Initialize the inflation state with an explicit flag to govern the handling of RFC1950 header bytes.

By default, the RFC1950 header is expected. If you want to read a zlib stream you should specify true for expectRfc1950Header. If you have a deflate stream, you will want to specify false. It is only necessary to invoke this initializer explicitly if you want to specify false.

InitializeInflate ( int windowBits ) : int

Initialize the ZlibCodec for inflation, with the specified number of window bits.

InitializeInflate ( int windowBits, bool expectRfc1950Header ) : int

Initialize the inflation state with an explicit flag to govern the handling of RFC1950 header bytes.

If you want to read a zlib stream you should specify true for expectRfc1950Header. If you have a deflate stream, you will want to specify false.

SetDeflateParams ( CompressionLevel level, CompressionStrategy strategy ) : int

Set the CompressionStrategy and CompressionLevel for a deflation session.

SetDictionary ( byte dictionary ) : int

Set the dictionary to be used for either Inflation or Deflation.

SyncInflate ( ) : int

I don't know what this does!

ZlibCodec ( ) : System

Create a ZlibCodec.

If you use this default constructor, you will later have to explicitly call InitializeInflate() or InitializeDeflate() before using the ZlibCodec to compress or decompress.

ZlibCodec ( CompressionMode mode ) : System

Create a ZlibCodec that either compresses or decompresses.

Private Methods

Method Description
flush_pending ( ) : void
read_buf ( byte buf, int start, int size ) : int

Method Details

Deflate() public method

Deflate one batch of data.
You must have set InputBuffer and OutputBuffer before calling this method.
public Deflate ( int flush ) : int
flush int whether to flush all data as you deflate. Generally you will want to /// use Z_NO_FLUSH here, in a series of calls to Deflate(), and then call EndDeflate() to /// flush everything. ///
return int

EndDeflate() public method

End a deflation session.
Call this after making a series of one or more calls to Deflate(). All buffers are flushed.
public EndDeflate ( ) : int
return int

EndInflate() public method

Ends an inflation session.
Call this after successively calling Inflate(). This will cause all buffers to be flushed. After calling this you cannot call Inflate() without a intervening call to one of the InitializeInflate() overloads.
public EndInflate ( ) : int
return int

Free() public method

public Free ( ) : void
return void

Inflate() public method

Inflate the data in the InputBuffer, placing the result in the OutputBuffer.
You must have set InputBuffer and OutputBuffer, NextIn and NextOut, and AvailableBytesIn and AvailableBytesOut before calling this method.
public Inflate ( int f ) : int
f int I think you want to set this to Z_NO_FLUSH.
return int

InitializeDeflate() public method

Initialize the ZlibCodec for deflation operation.
The codec will use the MAX window bits and the default level of compression.
public InitializeDeflate ( ) : int
return int

InitializeDeflate() public method

Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel.
The codec will use the MAX window bits and the specified CompressionLevel.
public InitializeDeflate ( CompressionLevel level ) : int
level CompressionLevel The compression level for the codec.
return int

InitializeDeflate() public method

Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel, and the explicit flag governing whether to emit an RFC1950 header byte pair.
The codec will use the MAX window bits and the specified CompressionLevel.
public InitializeDeflate ( CompressionLevel level, bool wantRfc1950Header ) : int
level CompressionLevel The compression level for the codec.
wantRfc1950Header bool whether to emit an initial RFC1950 byte pair in the compressed stream.
return int

InitializeDeflate() public method

Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel, and the specified number of window bits.
The codec will use the specified number of window bits and the specified CompressionLevel.
public InitializeDeflate ( CompressionLevel level, int bits ) : int
level CompressionLevel The compression level for the codec.
bits int the number of window bits to use. If you don't know what this means, don't use this method.
return int

InitializeDeflate() public method

Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel, the specified number of window bits, and the explicit flag governing whether to emit an RFC1950 header byte pair.
public InitializeDeflate ( CompressionLevel level, int bits, bool wantRfc1950Header ) : int
level CompressionLevel The compression level for the codec.
bits int the number of window bits to use. If you don't know what this means, don't use this method.
wantRfc1950Header bool whether to emit an initial RFC1950 byte pair in the compressed stream.
return int

InitializeInflate() public method

Initialize the inflation state.
It is not necessary to call this before using the ZlibCodec to inflate data; It is implicitly called when you call the constructor.
public InitializeInflate ( ) : int
return int

InitializeInflate() public method

Initialize the inflation state with an explicit flag to govern the handling of RFC1950 header bytes.
By default, the RFC1950 header is expected. If you want to read a zlib stream you should specify true for expectRfc1950Header. If you have a deflate stream, you will want to specify false. It is only necessary to invoke this initializer explicitly if you want to specify false.
public InitializeInflate ( bool expectRfc1950Header ) : int
expectRfc1950Header bool whether to expect an RFC1950 header byte pair when reading the stream of data to be inflated.
return int

InitializeInflate() public method

Initialize the ZlibCodec for inflation, with the specified number of window bits.
public InitializeInflate ( int windowBits ) : int
windowBits int The number of window bits to use. If you need to ask what that is, /// then you shouldn't be calling this initializer.
return int

InitializeInflate() public method

Initialize the inflation state with an explicit flag to govern the handling of RFC1950 header bytes.
If you want to read a zlib stream you should specify true for expectRfc1950Header. If you have a deflate stream, you will want to specify false.
public InitializeInflate ( int windowBits, bool expectRfc1950Header ) : int
windowBits int The number of window bits to use. If you need to ask what that is, /// then you shouldn't be calling this initializer.
expectRfc1950Header bool whether to expect an RFC1950 header byte pair when reading /// the stream of data to be inflated.
return int

SetDeflateParams() public method

Set the CompressionStrategy and CompressionLevel for a deflation session.
public SetDeflateParams ( CompressionLevel level, CompressionStrategy strategy ) : int
level CompressionLevel the level of compression to use.
strategy CompressionStrategy the strategy to use for compression.
return int

SetDictionary() public method

Set the dictionary to be used for either Inflation or Deflation.
public SetDictionary ( byte dictionary ) : int
dictionary byte The dictionary bytes to use.
return int

SyncInflate() public method

I don't know what this does!
public SyncInflate ( ) : int
return int

ZlibCodec() public method

Create a ZlibCodec.
If you use this default constructor, you will later have to explicitly call InitializeInflate() or InitializeDeflate() before using the ZlibCodec to compress or decompress.
public ZlibCodec ( ) : System
return System

ZlibCodec() public method

Create a ZlibCodec that either compresses or decompresses.
public ZlibCodec ( CompressionMode mode ) : System
mode CompressionMode /// Indicates whether the codec should compress (deflate) or decompress (inflate). ///
return System

Property Details

AvailableBytesIn public property

The number of bytes available in the InputBuffer, starting at NextIn.
Generally you should set this to InputBuffer.Length before the first Inflate() or Deflate() call. The class will update this number as calls to Inflate/Deflate are made.
public int AvailableBytesIn
return int

AvailableBytesOut public property

The number of bytes available in the OutputBuffer, starting at NextOut.
Generally you should set this to OutputBuffer.Length before the first Inflate() or Deflate() call. The class will update this number as calls to Inflate/Deflate are made.
public int AvailableBytesOut
return int

InputBuffer public property

The buffer from which data is taken.
public byte[] InputBuffer
return byte[]

Message public property

used for diagnostics, when something goes wrong!
public String,System Message
return System.String

NextIn public property

An index into the InputBuffer array, indicating where to start reading.
public int NextIn
return int

NextOut public property

An index into the OutputBuffer array, indicating where to start writing.
public int NextOut
return int

OutputBuffer public property

Buffer to store output data.
public byte[] OutputBuffer
return byte[]

TotalBytesIn public property

Total number of bytes read so far, through all calls to Inflate()/Deflate().
public long TotalBytesIn
return long

TotalBytesOut public property

Total number of bytes written to the output so far, through all calls to Inflate()/Deflate().
public long TotalBytesOut
return long