Xceed Zip for COM/ActiveX on x86/x64 Documentation
Xceed Compression control reference / Xceed Compression control methods / Compress method
    Compress method

    Description

    The Compress method compresses data entirely in memory, without dealing with files. It supports streaming data and can also encrypt data while it is compressing it.

    Declaration (ActiveX)  
    Method Compress(vaSource As Variant, vaCompressed As Variant, bEndOfData As Boolean) As xcdCompressionError
    
    Declaration (DLL API)  
    int XcCompress( HXCEEDCMP hComp, const BYTE* pcSource, DWORD dwSourceSize, BYTE** ppcCompressed, 
    DWORD* pdwCompressedSize, BOOL bEndOfData )

    Parameters

    Parameter Description
    vaSource  The data to compress. The variant can contain a string or a byte array.
    vaCompressed  The compressed data is placed here, in the form of a byte array variant. The content of the vaCompressed parameter is always cleared before writing the compressed data to it.
    bEndOfData  Set this parameter to True if you only have a single block of data to compress and require that the compressed data be immediately written to the vaCompressed parameter. Set this parameter to False if you are dealing with streaming data. 
     
    The bEndOfData parameter allows you to provide the compression engine with data to compress as it becomes available. Whenever you have some new data to compress, put your data in the vaSource parameter, set bEndOfData to False, then call the Compress method. When the call completes, the compression engine may or may not have writen any compressed data to the vaCompressed parameter. If there is data in the vaCompressed parameter, you must grab it before calling the Compress method again, because if there is new compressed data, it will overwrite data currently present in the vaCompressed parameter. When your last block of data is sent to the Compress method in this fashion, set bEndOfData to True. The compression engine will flush all remaining compressed data to the vaCompressed parameter's variable.

    Return values

    See the xcdCompressionError topic for a description of the possible return values.

    Other features

    If you want to encrypt the data while it is being compressed, set the EncryptionPassword property.

    To control the amount of compression applied, set the CompressionLevel property.

    If you are compressing a stream of data, and you want to force the compression engine to flush its output buffers right away without obtaining more uncompressed data, you can do this by calling the Compress method with an empty vaSource variable.

    The compressed data contains a 32-bit checksum that is used by the Uncompress method to make sure that the data uncompresses properly and is identical to the original uncompressed data sent to the Compress method.

    Remarks

    With Visual Basic, it is often necessary to convert the resulting compressed data from a Variant to a Byte Array before saving it or transmitting it. VB6 makes it particularly easy to do the conversion: If you have a variant named (for example) CompressedDataVariant, you can convert it to a Byte Array with the following code:

    Visual Basic Copy Code

    Dim CompressedDataArray() As Byte
    ReDim CompressedDataArray(1 To UBound(CompressedDataVariant)) As Byte 

    CompressedDataArray = CompressedDataVariant
    ' Now you can output your compressed data (save it, transmit it..)

    With Microsoft Access, you can place the compressed data in either a Memo field or an OLE Object field. Using an OLE Object field in a table is the easiest: You can directly assign your data to the field and conversion is automatic. To assign the compressed data variant to a Memo field, use the "AppendChunk" function in Access.

    Applicable properties

    The Xceed Compression control's EncryptionPassword, CompressionLevel properties.

    Events triggered

    None

    See Also