C# Class ComponentAce.Compression.Libs.ZLib.ZStream

ZStream is used to store user data to compress/decompress.
Show file Open project: jschementi/iron Class Usage Examples

Private Properties

Property Type Description

Public Methods

Method Description
deflate ( FlushStrategy flush ) : int

Deflate compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce some output latency (reading input without producing any output) except when forced to flush.

The detailed semantics are as follows. deflate performs one or both of the following actions: Compress more input starting at next_in and update next_in and avail_in accordingly. If not all input can be processed (because there is not enough room in the output buffer), next_in and avail_in are updated and processing will resume at this point for the next call of deflate. Provide more output starting at next_out and update next_out and avail_out accordingly. This action is forced if the parameter flush is non zero. Forcing flush frequently degrades the compression ratio, so this parameter should be set only when necessary (in interactive applications). Some output may be provided even if flush is not set.

Before the call of , the application should ensure that at least one of the actions is possible, by providing more input and/or consuming more output, and updating avail_in or avail_out accordingly ; avail_out should never be zero before the call. The application can consume the compressed output when it wants, for example when the output buffer is full (avail_out == 0), or after each call of deflate. If deflate returns ZLibResultCode.Z_OK and with zero avail_out, it must be called again after making room in the output buffer because there might be more output pending.

If the parameter flush is set to FlushStrategy.Z_SYNC_FLUSH, all pending output is flushed to the output buffer and the output is aligned on a byte boundary, so that the decompressor can get all input data available so far. (In particular avail_in is zero after the call if enough output space has been provided before the call.) Flushing may degrade compression for some compression algorithms and so it should be used only when necessary.

If flush is set to FlushStrategy.Z_FULL_FLUSH, all output is flushed as with FlushStrategy.Z_SYNC_FLUSH, and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if random access is desired. Using FlushStrategy.Z_FULL_FLUSH too often can seriously degrade the compression.

deflateEnd ( ) : int

All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending output.

deflateInit ( int level ) : int

Initializes the internal stream state for compression.

deflateInit ( int level, int bits ) : int

Initializes the internal stream state for compression.

deflateParams ( int level, CompressionStrategy strategy ) : int

Dynamically update the compression level and compression strategy. The interpretation of level is as in deflateInit(int). This can be used to switch between compression and straight copy of the input data, or to switch to a different kind of input data requiring a different strategy. If the compression level is changed, the input available so far is compressed with the old level (and may be flushed); the new level will take effect only at the next call of deflate

Before the call of deflateParams, the stream state must be set as for a call of deflate, since the currently available input may have to be compressed and flushed. In particular, avail_out must be non-zero.

deflateSetDictionary ( byte dictionary, int dictLength ) : int

Initializes the compression dictionary from the given byte sequence without producing any compressed output. This function must be called immediately after deflateInit(int), before any call of deflate. The compressor and decompressor must use exactly the same dictionary (see inflateSetDictionary).

The dictionary should consist of strings (byte sequences) that are likely to be encountered later in the data to be compressed, with the most commonly used strings preferably put towards the end of the dictionary. Using a dictionary is most useful when the data to be compressed is short and can be predicted with good accuracy; the data can then be compressed better than with the default empty dictionary.

Depending on the size of the compression data structures selected by deflateInit(int), a part of the dictionary may in effect be discarded, for example if the dictionary is larger than the window size in deflate. Thus the strings most likely to be useful should be put at the end of the dictionary, not at the front.

Upon return of this function, adler is set to the Adler32 value of the dictionary; the decompresser may later use this value to determine which dictionary has been used by the compressor. (The Adler32 value applies to the whole dictionary even if only a subset of the dictionary is actually used by the compressor.)

flush_pending ( ) : void

Flush as much pending output as possible. All deflate output goes through this function so some applications may wish to modify it to avoid allocating a large next_out buffer and copying into it.

free ( ) : void

Frees all inner ZStream buffers.

inflate ( FlushStrategy flush ) : int

This method decompresses as much data as possible, and stops when the input buffer (next_in) becomes empty or the output buffer (next_out) becomes full. It may some introduce some output latency (reading input without producing any output) except when forced to flush.

The detailed semantics are as follows. inflate performs one or both of the following actions:

Decompress more input starting at ZStream.next_in and update ZStream.next_in and ZStream.avail_in accordingly. If not all input can be processed (because there is not enough room in the output buffer), next_in is updated and processing will resume at this point for the next call of inflate. Provide more output starting at next_out and update ZStream.next_out and ZStream.avail_out accordingly. ZStream.inflate provides as much output as possible, until there is no more input data or no more space in the output buffer (see below about the flush parameter).

Before the call of inflate, the application should ensure that at least one of the actions is possible, by providing more input and/or consuming more output, and updating the next_* and avail_* values accordingly. The application can consume the uncompressed output when it wants, for example when the output buffer is full (avail_out == 0), or after each call of inflate. If inflate returns ZLibResultCode.Z_OK and with zero avail_out, it must be called again after making room in the output buffer because there might be more output pending.

If the parameter flush is set to FlushStrategy.Z_SYNC_FLUSH, inflate flushes as much output as possible to the output buffer. The flushing behavior of inflate is not specified for values of the flush parameter other than FlushStrategy.Z_SYNC_FLUSH and FlushStrategy.Z_FINISH, but the current implementation actually flushes as much output as possible anyway.

inflate should normally be called until it returns ZLibResultCode.Z_STREAM_END or an error. However if all decompression is to be performed in a single step (a single call of inflate), the parameter flush should be set to FlushStrategy.Z_FINISH. In this case all pending input is processed and all pending output is flushed; avail_out must be large enough to hold all the uncompressed data. (The size of the uncompressed data may have been saved by the compressor for this purpose.) The next operation on this stream must be inflateEnd to deallocate the decompression state. The use of FlushStrategy.Z_FINISH is never required, but can be used to inform inflate that a faster routine may be used for the single inflate call.

If a preset dictionary is needed at this point (see inflateSetDictionary), inflate sets strm-adler to the adler32 checksum of the dictionary chosen by the compressor and returns ZLibResultCode.Z_NEED_DICT; otherwise it sets strm->adler to the adler32 checksum of all output produced so far (that is, total_out bytes) and returns ZLibResultCode.Z_OK, ZLibResultCode.Z_STREAM_END or an error code as described below. At the end of the stream, inflate) checks that its computed adler32 checksum is equal to that saved by the compressor and returns ZLibResultCode.Z_STREAM_END only if the checksum is correct.

inflateEnd ( ) : int

All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending output.

inflateInit ( ) : int

Initializes the internal stream state for decompression. The fields next_in, avail_in must be initialized before by the caller. If next_in is not null and avail_in is large enough (the exact value depends on the compression method), inflateInit() determines the compression method from the ZLib header and allocates all data structures accordingly; otherwise the allocation will be deferred to the first call of inflate.

inflateInit ( int windowBits ) : int

This is another version of inflateInit() with an extra parameter. The fields next_in, avail_in must be initialized before by the caller. If next_in is not null and avail_in is large enough (the exact value depends on the compression method), inflateInit(int) determines the compression method from the ZLib header and allocates all data structures accordingly; otherwise the allocation will be deferred to the first call of inflate.

inflateSetDictionary ( byte dictionary, int dictLength ) : int

Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of inflate if this call returned ZLibResultCode.Z_NEED_DICT. The dictionary chosen by the compressor can be determined from the Adler32 value returned by this call of inflate. The compressor and decompresser must use exactly the same dictionary.

inflateSync ( ) : int

Skips invalid compressed data until a full flush point (see the description of deflate with Z_FULL_FLUSH) can be found, or until all available input is skipped. No output is provided.

read_buf ( byte buf, int start, int size ) : int

Read a new buffer from the current input stream, update the adler32 and total number of bytes read. All deflate input goes through this function so some applications may wish to modify it to avoid allocating a large next_in buffer and copying from it.

Method Details

deflate() public method

Deflate compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce some output latency (reading input without producing any output) except when forced to flush.

The detailed semantics are as follows. deflate performs one or both of the following actions: Compress more input starting at next_in and update next_in and avail_in accordingly. If not all input can be processed (because there is not enough room in the output buffer), next_in and avail_in are updated and processing will resume at this point for the next call of deflate. Provide more output starting at next_out and update next_out and avail_out accordingly. This action is forced if the parameter flush is non zero. Forcing flush frequently degrades the compression ratio, so this parameter should be set only when necessary (in interactive applications). Some output may be provided even if flush is not set.

Before the call of , the application should ensure that at least one of the actions is possible, by providing more input and/or consuming more output, and updating avail_in or avail_out accordingly ; avail_out should never be zero before the call. The application can consume the compressed output when it wants, for example when the output buffer is full (avail_out == 0), or after each call of deflate. If deflate returns ZLibResultCode.Z_OK and with zero avail_out, it must be called again after making room in the output buffer because there might be more output pending.

If the parameter flush is set to FlushStrategy.Z_SYNC_FLUSH, all pending output is flushed to the output buffer and the output is aligned on a byte boundary, so that the decompressor can get all input data available so far. (In particular avail_in is zero after the call if enough output space has been provided before the call.) Flushing may degrade compression for some compression algorithms and so it should be used only when necessary.

If flush is set to FlushStrategy.Z_FULL_FLUSH, all output is flushed as with FlushStrategy.Z_SYNC_FLUSH, and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if random access is desired. Using FlushStrategy.Z_FULL_FLUSH too often can seriously degrade the compression.

public deflate ( FlushStrategy flush ) : int
flush FlushStrategy The flush strategy to use.
return int

deflateEnd() public method

All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending output.
public deflateEnd ( ) : int
return int

deflateInit() public method

Initializes the internal stream state for compression.
public deflateInit ( int level ) : int
level int An integer value from 0 to 9 indicating the desired compression level.
return int

deflateInit() public method

Initializes the internal stream state for compression.
public deflateInit ( int level, int bits ) : int
level int An integer value from 0 to 9 indicating the desired compression level.
bits int The windowBits parameter is the base two logarithm of the window size (the size of the history buffer). It should be in the /// range 8..15 for this version of the library. Larger values of this parameter result in better compression at the expense of memory usage. /// The default value is 15 if deflateInit is used instead.
return int

deflateParams() public method

Dynamically update the compression level and compression strategy. The interpretation of level is as in deflateInit(int). This can be used to switch between compression and straight copy of the input data, or to switch to a different kind of input data requiring a different strategy. If the compression level is changed, the input available so far is compressed with the old level (and may be flushed); the new level will take effect only at the next call of deflate
Before the call of deflateParams, the stream state must be set as for a call of deflate, since the currently available input may have to be compressed and flushed. In particular, avail_out must be non-zero.
public deflateParams ( int level, CompressionStrategy strategy ) : int
level int An integer value indicating the desired compression level.
strategy CompressionStrategy A flush strategy to use.
return int

deflateSetDictionary() public method

Initializes the compression dictionary from the given byte sequence without producing any compressed output. This function must be called immediately after deflateInit(int), before any call of deflate. The compressor and decompressor must use exactly the same dictionary (see inflateSetDictionary).

The dictionary should consist of strings (byte sequences) that are likely to be encountered later in the data to be compressed, with the most commonly used strings preferably put towards the end of the dictionary. Using a dictionary is most useful when the data to be compressed is short and can be predicted with good accuracy; the data can then be compressed better than with the default empty dictionary.

Depending on the size of the compression data structures selected by deflateInit(int), a part of the dictionary may in effect be discarded, for example if the dictionary is larger than the window size in deflate. Thus the strings most likely to be useful should be put at the end of the dictionary, not at the front.

Upon return of this function, adler is set to the Adler32 value of the dictionary; the decompresser may later use this value to determine which dictionary has been used by the compressor. (The Adler32 value applies to the whole dictionary even if only a subset of the dictionary is actually used by the compressor.)

public deflateSetDictionary ( byte dictionary, int dictLength ) : int
dictionary byte A byte array - a dictionary.
dictLength int The length of the dictionary byte array
return int

flush_pending() public method

Flush as much pending output as possible. All deflate output goes through this function so some applications may wish to modify it to avoid allocating a large next_out buffer and copying into it.
public flush_pending ( ) : void
return void

free() public method

Frees all inner ZStream buffers.
public free ( ) : void
return void

inflate() public method

This method decompresses as much data as possible, and stops when the input buffer (next_in) becomes empty or the output buffer (next_out) becomes full. It may some introduce some output latency (reading input without producing any output) except when forced to flush.

The detailed semantics are as follows. inflate performs one or both of the following actions:

Decompress more input starting at ZStream.next_in and update ZStream.next_in and ZStream.avail_in accordingly. If not all input can be processed (because there is not enough room in the output buffer), next_in is updated and processing will resume at this point for the next call of inflate. Provide more output starting at next_out and update ZStream.next_out and ZStream.avail_out accordingly. ZStream.inflate provides as much output as possible, until there is no more input data or no more space in the output buffer (see below about the flush parameter).

Before the call of inflate, the application should ensure that at least one of the actions is possible, by providing more input and/or consuming more output, and updating the next_* and avail_* values accordingly. The application can consume the uncompressed output when it wants, for example when the output buffer is full (avail_out == 0), or after each call of inflate. If inflate returns ZLibResultCode.Z_OK and with zero avail_out, it must be called again after making room in the output buffer because there might be more output pending.

If the parameter flush is set to FlushStrategy.Z_SYNC_FLUSH, inflate flushes as much output as possible to the output buffer. The flushing behavior of inflate is not specified for values of the flush parameter other than FlushStrategy.Z_SYNC_FLUSH and FlushStrategy.Z_FINISH, but the current implementation actually flushes as much output as possible anyway.

inflate should normally be called until it returns ZLibResultCode.Z_STREAM_END or an error. However if all decompression is to be performed in a single step (a single call of inflate), the parameter flush should be set to FlushStrategy.Z_FINISH. In this case all pending input is processed and all pending output is flushed; avail_out must be large enough to hold all the uncompressed data. (The size of the uncompressed data may have been saved by the compressor for this purpose.) The next operation on this stream must be inflateEnd to deallocate the decompression state. The use of FlushStrategy.Z_FINISH is never required, but can be used to inform inflate that a faster routine may be used for the single inflate call.

If a preset dictionary is needed at this point (see inflateSetDictionary), inflate sets strm-adler to the adler32 checksum of the dictionary chosen by the compressor and returns ZLibResultCode.Z_NEED_DICT; otherwise it sets strm->adler to the adler32 checksum of all output produced so far (that is, total_out bytes) and returns ZLibResultCode.Z_OK, ZLibResultCode.Z_STREAM_END or an error code as described below. At the end of the stream, inflate) checks that its computed adler32 checksum is equal to that saved by the compressor and returns ZLibResultCode.Z_STREAM_END only if the checksum is correct.

public inflate ( FlushStrategy flush ) : int
flush FlushStrategy Flush strategy to use.
return int

inflateEnd() public method

All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending output.
public inflateEnd ( ) : int
return int

inflateInit() public method

Initializes the internal stream state for decompression. The fields next_in, avail_in must be initialized before by the caller. If next_in is not null and avail_in is large enough (the exact value depends on the compression method), inflateInit() determines the compression method from the ZLib header and allocates all data structures accordingly; otherwise the allocation will be deferred to the first call of inflate.
public inflateInit ( ) : int
return int

inflateInit() public method

This is another version of inflateInit() with an extra parameter. The fields next_in, avail_in must be initialized before by the caller. If next_in is not null and avail_in is large enough (the exact value depends on the compression method), inflateInit(int) determines the compression method from the ZLib header and allocates all data structures accordingly; otherwise the allocation will be deferred to the first call of inflate.
public inflateInit ( int windowBits ) : int
windowBits int The windowBits parameter is the base two logarithm of the maximum window size (the size of the history buffer). /// It should be in the range 8..15 for this version of the library. The default value is 15 if is used instead. /// If a compressed stream with a larger window size is given as input, will return with the error code /// instead of trying to allocate a larger window.
return int

inflateSetDictionary() public method

Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of inflate if this call returned ZLibResultCode.Z_NEED_DICT. The dictionary chosen by the compressor can be determined from the Adler32 value returned by this call of inflate. The compressor and decompresser must use exactly the same dictionary.
public inflateSetDictionary ( byte dictionary, int dictLength ) : int
dictionary byte A byte array - a dictionary.
dictLength int The length of the dictionary.
return int

inflateSync() public method

Skips invalid compressed data until a full flush point (see the description of deflate with Z_FULL_FLUSH) can be found, or until all available input is skipped. No output is provided.
public inflateSync ( ) : int
return int

read_buf() public method

Read a new buffer from the current input stream, update the adler32 and total number of bytes read. All deflate input goes through this function so some applications may wish to modify it to avoid allocating a large next_in buffer and copying from it.
public read_buf ( byte buf, int start, int size ) : int
buf byte
start int
size int
return int