Indy 9 | Content | Index | Reference

TIdCompressionIntercept
Hierarchy, Properties, Methods, Events, Unit: IdCompressionIntercept
Implements an intercept that compresses a data stream using zlib.

    TIdCompressionIntercept = class(TIdConnectionIntercept)

Unit
IdCompressionIntercept
Description
TIdCompressionIntercept is a TIdConnectionIntercept descendant that implements an Indy intercept component that compresses a data stream using the open-source zlib compression library. Set the CompressionLevel property to a value between 1 and 9 to enable compressing of the data stream. A setting of 0(zero) disables compression and the component is dormant. The sender *and* received must have compression enabled in order to properly decompress the data stream. They do *not* have to use the same CompressionLevel as long as they are both set to a value between 1 and 9.

In order for this file to compile on Windows, the follow .obj files *must* be provided as delivered with this file:

- deflate.obj

- inflate.obj

- inftrees.obj

- trees.obj

- adler32.obj

- infblock.obj

- infcodes.obj

- infutil.obj

- inffast.obj

On Linux, the shared-object file libz.so.1 *must* be available on the system. Most modern Linux distributions include this file.

You may sometimes get the following compiler errors with this file:

        IdCompressionIntercept.pas(331) Error: Incompatible types
        IdCompressionIntercept.pas(152) Error: Unsatisfied forward or external declaration: '_tr_init'
        IdCompressionIntercept.pas(153) Error: Unsatisfied forward or external declaration: '_tr_tally'
        IdCompressionIntercept.pas(154) Error: Unsatisfied forward or external declaration: '_tr_flush_block'
        IdCompressionIntercept.pas(155) Error: Unsatisfied forward or external declaration: '_tr_align'
        IdCompressionIntercept.pas(156) Error: Unsatisfied forward or external declaration: '_tr_stored_block'
        IdCompressionIntercept.pas(157) Error: Unsatisfied forward or external declaration: 'adler32'
        IdCompressionIntercept.pas(158) Error: Unsatisfied forward or external declaration: 'inflate_blocks_new'
        IdCompressionIntercept.pas(159) Error: Unsatisfied forward or external declaration: 'inflate_blocks'
        IdCompressionIntercept.pas(160) Error: Unsatisfied forward or external declaration: 'inflate_blocks_reset'
        IdCompressionIntercept.pas(161) Error: Unsatisfied forward or external declaration: 'inflate_blocks_free'
        IdCompressionIntercept.pas(162) Error: Unsatisfied forward or external declaration: 'inflate_set_dictionary'
        IdCompressionIntercept.pas(163) Error: Unsatisfied forward or external declaration: 'inflate_trees_bits'
        IdCompressionIntercept.pas(164) Error: Unsatisfied forward or external declaration: 'inflate_trees_dynamic'
        IdCompressionIntercept.pas(165) Error: Unsatisfied forward or external declaration: 'inflate_trees_fixed'
        IdCompressionIntercept.pas(166) Error: Unsatisfied forward or external declaration: 'inflate_trees_free'
        IdCompressionIntercept.pas(167) Error: Unsatisfied forward or external declaration: 'inflate_codes_new'
        IdCompressionIntercept.pas(168) Error: Unsatisfied forward or external declaration: 'inflate_codes'
        IdCompressionIntercept.pas(169) Error: Unsatisfied forward or external declaration: 'inflate_codes_free'
        IdCompressionIntercept.pas(170) Error: Unsatisfied forward or external declaration: '_inflate_mask'
        IdCompressionIntercept.pas(171) Error: Unsatisfied forward or external declaration: 'inflate_flush'
        IdCompressionIntercept.pas(172) Error: Unsatisfied forward or external declaration: 'inflate_fast'
        IdCompressionIntercept.pas(189) Error: Unsatisfied forward or external declaration: 'deflateInit_'
        IdCompressionIntercept.pas(196) Error: Unsatisfied forward or external declaration: 'deflate'
        IdCompressionIntercept.pas(203) Error: Unsatisfied forward or external declaration: 'deflateEnd'
        IdCompressionIntercept.pas(213) Error: Unsatisfied forward or external declaration: 'inflateInit_'
        IdCompressionIntercept.pas(220) Error: Unsatisfied forward or external declaration: 'inflate'
        IdCompressionIntercept.pas(227) Error: Unsatisfied forward or external declaration: 'inflateEnd'
        IdCompressionIntercept.pas(234) Error: Unsatisfied forward or external declaration: 'inflateReset'
        Indy40.dpk(196) Fatal: Could not compile used unit 'IdCompressionIntercept.pas'

Do not be alarmed. This is due to a bug in DCC32 in Delphi 4, 5, 6, plus C++Builder, 4, 5, and 6.

There is a workaround for this issue. The workaround is to compile this unit separately from the other units and than build Indy with a command such as DCC32 using the /M parameter. DO not use the /B parameter as that does force everything to be recompiled triggering the DCC32 error.

The batch files FULLC4.BAT, FULLC5.BAT, FULLC6.BAT, FULLD4.BAT, FULLD5.BAT and FULLD6.BAT now have the workaround in them so we recommend that you use those to build Indy.

Borland is aware of the issue.

Original Author: Allen Bauer

This source file is submitted to the Indy project on behalf of Borland Sofware Corporation. No warranties, express or implied are given with this source file.

TIdCompressionIntercept.CompressionLevel
TIdCompressionIntercept, See Also
Represents the compression level applied the data stream for the intercept.

    property CompressionLevel: TCompressionLevel;

Description
CompressionLevel is a TCompressionLevel property that represents the compression level to be applied when transforming data using Send or Receive. Set CompressionLevel to a value between 1 and 9 to enable compressing of the data stream for intercept. When CompressionLevel is 0 (zero), compression is disabled and the intercept is dormant.

Both the sender and receiver must have compression enabled in order to properly decompress the data stream for the intercept. They do not have to use the same CompressionLevel as long as they are both set to a value between 1 and 9.

Changing the value in CompressionLevel insures that the internal compression and decompression records are reset and cleared. The new value for CompressionLevel will also be forced into the range allowed by the TCompressionLevel enumeration.

TIdCompressionIntercept.Destroy
TIdCompressionIntercept
Frees the object instance.

    destructor Destroy; override;

Description
Destroy is the destructor for the object instance. Destroy insures that the internal ZLib compression and decompression records are reset and cleared. Destroy also frees Pointers allocated to the internal Send and Receive buffers for the compression intercept. Destroy calls the inherited Destroy method prior to exiting.

TIdCompressionIntercept.Receive
TIdCompressionIntercept, See Also
Decompresses stream data for the intercept using ZLib.

    procedure Receive(ABuffer: TStream); override;

Parameters
ABuffer: TStream
Stream to use for input and output values for the operation.
Description
Receive is an overridden procedure in TIdCompressionIntercept that implements ZLib decompression of data received in ABuffer. When CompressionLevel is 0 (zero), the compression intercept is dormant and no decompression is performed for values in ABuffer.

Receive initializes the internal ZLib compression and decompression records when they have been assigned in the object instance. Receive reads data from the internal receive buffer using a 2,048 byte block that expands by 1024 bytes on successive reads until the end of the ZLib stream is reached. If a stream, data, or memory error occurs while decompressing the contents of the receive buffer, a EIdDecompressionError exception will be raised with the message RSZLDecompressionError.

On successful completion of receive buffer decompression, ABuffer is resized and the decompressed data is returned to the stream.

TIdCompressionIntercept.Send
TIdCompressionIntercept, See Also
Compresses stream data for the intercept using ZLib.

    procedure Send(ABuffer: TStream); override;

Parameters
ABuffer: TStream
Stream to use for input and output values for the operation.
Description
Send is an overridden procedure in TIdCompressionIntercept that implements ZLib compression of stream data received in ABuffer. When CompressionLevel is 0 (zero), the compression intercept is dormant and no compression is performed for values in ABuffer.

Send initializes the internal ZLib compression and decompression records when they have been assigned in the object instance. Send insures that the internal Send buffer is large enough to hold the stream data in ABuffer. Send reads data from the internal send buffer using a 2,048 byte block that expands by 1024 bytes on successive reads until the end of the ZLib stream is reached.

If a stream, data, or memory error occurs while compressing the contents of the send buffer, a EIdCompressionError exception will be raised with the message RSZLCompressionError.

On successful completion of send buffer compression, ABuffer is resized and the compressed data is returned to the stream.

Created with Doc-O-Matic 2 donated to Project JEDI. Commercial license available from the Doc-O-Matic site.