CompressData Method  
 

Compress the contents of the specified string or byte array.

Syntax

object.CompressData( InputData, OutputData )

Parameters

InputData
A string or byte array that contains the data to be compressed.
OutputData
A string or byte array that is passed by reference and will contain the compressed data when the method returns. If this parameter is a string or variant type, the compressed data will be automatically base64 encoded. If this parameter is a byte array, the compressed data will be copied into the array.

Return Value

This method returns the number of bytes of compressed data that was copied into the output buffer. If the input buffer is a zero-length string or an empty array, the method will return zero. If an error occurs, the method will return -1. Check the value of the LastError property to determine the specific error that has occurred.

Remarks

The CompressData method compresses the contents of a string or byte array in memory, rather than using a temporary file. The type of variable passed to the method as the output buffer determines whether the data is base644 encoded or not. If the output buffer is a string type then the compressed data will be automatically encoded to ensure that it can be safely represented as a string. If the output buffer is a byte array, the compressed data will be copied into the array as-is without any encoding. If the caller specifies a fixed-size byte array as the output buffer, the array must be large enough to contain all of the compressed data, otherwise the method will fail.

The return value from this method should always be checked to ensure that the data was successfully compressed. An application should never assume that the output buffer contains valid compressed data unless the return value is greater than zero. The compressed data is not returned in a format that is recognized by third-party applications such as PKZip or WinZip. To expand the compressed data, pass the contents of the output buffer to the ExpandData method.

See Also

CompressFile Method, DecryptData Method, EncryptData Method, ExpandData Method, ExpandFile Method