Show / Hide Table of Contents

Class Deflater

This is the Deflater class. The deflater class compresses input with the deflate algorithm described in RFC 1951. It has several compression levels and three different strategies described below.

This class is not thread safe. This is inherent in the API, due to the split of deflate and setInput.

author of the original java version : Jochen Hoenicke

Inheritance
System.Object
Deflater
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: ICSharpCode.SharpZipLib.Zip.Compression
Assembly: ICSharpCode.SharpZipLib.dll
Syntax
public class Deflater

Constructors

| Improve this Doc View Source

Deflater()

Creates a new deflater with default compression level.

Declaration
public Deflater()
| Improve this Doc View Source

Deflater(Int32)

Creates a new deflater with given compression level.

Declaration
public Deflater(int level)
Parameters
Type Name Description
System.Int32 level

the compression level, a value between NO_COMPRESSION and BEST_COMPRESSION, or DEFAULT_COMPRESSION.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

if lvl is out of range.

| Improve this Doc View Source

Deflater(Int32, Boolean)

Creates a new deflater with given compression level.

Declaration
public Deflater(int level, bool noZlibHeaderOrFooter)
Parameters
Type Name Description
System.Int32 level

the compression level, a value between NO_COMPRESSION and BEST_COMPRESSION.

System.Boolean noZlibHeaderOrFooter

true, if we should suppress the Zlib/RFC1950 header at the beginning and the adler checksum at the end of the output. This is useful for the GZIP/PKZIP formats.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

if lvl is out of range.

Fields

| Improve this Doc View Source

BEST_COMPRESSION

The best and slowest compression level. This tries to find very long and distant string repetitions.

Declaration
public const int BEST_COMPRESSION = 9
Field Value
Type Description
System.Int32
| Improve this Doc View Source

BEST_SPEED

The worst but fastest compression level.

Declaration
public const int BEST_SPEED = 1
Field Value
Type Description
System.Int32
| Improve this Doc View Source

DEFAULT_COMPRESSION

The default compression level.

Declaration
public const int DEFAULT_COMPRESSION = -1
Field Value
Type Description
System.Int32
| Improve this Doc View Source

DEFLATED

The compression method. This is the only method supported so far. There is no need to use this constant at all.

Declaration
public const int DEFLATED = 8
Field Value
Type Description
System.Int32
| Improve this Doc View Source

NO_COMPRESSION

This level won't compress at all but output uncompressed blocks.

Declaration
public const int NO_COMPRESSION = 0
Field Value
Type Description
System.Int32

Properties

| Improve this Doc View Source

Adler

Gets the current adler checksum of the data that was processed so far.

Declaration
public int Adler { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

IsFinished

Returns true if the stream was finished and no more output bytes are available.

Declaration
public bool IsFinished { get; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

IsNeedingInput

Returns true, if the input buffer is empty. You should then call setInput(). NOTE: This method can also return true when the stream was finished.

Declaration
public bool IsNeedingInput { get; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

TotalIn

Gets the number of input bytes processed so far.

Declaration
public long TotalIn { get; }
Property Value
Type Description
System.Int64
| Improve this Doc View Source

TotalOut

Gets the number of output bytes so far.

Declaration
public long TotalOut { get; }
Property Value
Type Description
System.Int64

Methods

| Improve this Doc View Source

Deflate(Byte[])

Deflates the current input block with to the given array.

Declaration
public int Deflate(byte[] output)
Parameters
Type Name Description
System.Byte[] output

The buffer where compressed data is stored

Returns
Type Description
System.Int32

The number of compressed bytes added to the output, or 0 if either IsNeedingInput() or IsFinished returns true or length is zero.

| Improve this Doc View Source

Deflate(Byte[], Int32, Int32)

Deflates the current input block to the given array.

Declaration
public int Deflate(byte[] output, int offset, int length)
Parameters
Type Name Description
System.Byte[] output

Buffer to store the compressed data.

System.Int32 offset

Offset into the output array.

System.Int32 length

The maximum number of bytes that may be stored.

Returns
Type Description
System.Int32

The number of compressed bytes added to the output, or 0 if either needsInput() or finished() returns true or length is zero.

Exceptions
Type Condition
System.InvalidOperationException

If Finish() was previously called.

System.ArgumentOutOfRangeException

If offset or length don't match the array length.

| Improve this Doc View Source

Finish()

Finishes the deflater with the current input block. It is an error to give more input after this method was called. This method must be called to force all bytes to be flushed.

Declaration
public void Finish()
| Improve this Doc View Source

Flush()

Flushes the current input block. Further calls to deflate() will produce enough output to inflate everything in the current input block. This is not part of Sun's JDK so I have made it package private. It is used by DeflaterOutputStream to implement flush().

Declaration
public void Flush()
| Improve this Doc View Source

GetLevel()

Get current compression level

Declaration
public int GetLevel()
Returns
Type Description
System.Int32

Returns the current compression level

| Improve this Doc View Source

Reset()

Resets the deflater. The deflater acts afterwards as if it was just created with the same compression level and strategy as it had before.

Declaration
public void Reset()
| Improve this Doc View Source

SetDictionary(Byte[])

Sets the dictionary which should be used in the deflate process. This call is equivalent to

setDictionary(dict, 0, dict.Length)
.

Declaration
public void SetDictionary(byte[] dictionary)
Parameters
Type Name Description
System.Byte[] dictionary

the dictionary.

Exceptions
Type Condition
System.InvalidOperationException

if SetInput () or Deflate () were already called or another dictionary was already set.

| Improve this Doc View Source

SetDictionary(Byte[], Int32, Int32)

Sets the dictionary which should be used in the deflate process. The dictionary is a byte array containing strings that are likely to occur in the data which should be compressed. The dictionary is not stored in the compressed output, only a checksum. To decompress the output you need to supply the same dictionary again.

Declaration
public void SetDictionary(byte[] dictionary, int index, int count)
Parameters
Type Name Description
System.Byte[] dictionary

The dictionary data

System.Int32 index

The index where dictionary information commences.

System.Int32 count

The number of bytes in the dictionary.

Exceptions
Type Condition
System.InvalidOperationException

If SetInput () or Deflate() were already called or another dictionary was already set.

| Improve this Doc View Source

SetInput(Byte[])

Sets the data which should be compressed next. This should be only called when needsInput indicates that more input is needed. If you call setInput when needsInput() returns false, the previous input that is still pending will be thrown away. The given byte array should not be changed, before needsInput() returns true again. This call is equivalent to

setInput(input, 0, input.length)
.

Declaration
public void SetInput(byte[] input)
Parameters
Type Name Description
System.Byte[] input

the buffer containing the input data.

Exceptions
Type Condition
System.InvalidOperationException

if the buffer was finished() or ended().

| Improve this Doc View Source

SetInput(Byte[], Int32, Int32)

Sets the data which should be compressed next. This should be only called when needsInput indicates that more input is needed. The given byte array should not be changed, before needsInput() returns true again.

Declaration
public void SetInput(byte[] input, int offset, int count)
Parameters
Type Name Description
System.Byte[] input

the buffer containing the input data.

System.Int32 offset

the start of the data.

System.Int32 count

the number of data bytes of input.

Exceptions
Type Condition
System.InvalidOperationException

if the buffer was Finish()ed or if previous input is still pending.

| Improve this Doc View Source

SetLevel(Int32)

Sets the compression level. There is no guarantee of the exact position of the change, but if you call this when needsInput is true the change of compression level will occur somewhere near before the end of the so far given input.

Declaration
public void SetLevel(int level)
Parameters
Type Name Description
System.Int32 level

the new compression level.

| Improve this Doc View Source

SetStrategy(DeflateStrategy)

Sets the compression strategy. Strategy is one of DEFAULT_STRATEGY, HUFFMAN_ONLY and FILTERED. For the exact position where the strategy is changed, the same as for SetLevel() applies.

Declaration
public void SetStrategy(DeflateStrategy strategy)
Parameters
Type Name Description
DeflateStrategy strategy

The new compression strategy.

  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2000-2022 SharpZipLib Contributors