The following is a description of the aPLib compression functionality.
Compress length bytes of data from source to destination, using workmem as temporary storage.
The destination buffer should be large enough to hold aP_max_packed_size(length) bytes.
The workmem buffer should be aP_workmem_size(length) bytes large.
The callback function, callback, must take four parameters. The first is length, the second is the number of input bytes that has been compressed, the third is how many output bytes they have been compressed to, and the fourth is cbparam. If you do not have a callback, use NULL instead. If the callback returns a non-zero value then aP_pack() will continue compressing – if it returns zero, aP_pack() will stop and return APLIB_ERROR.
Parameters: |
|
---|---|
Returns: | length of compressed data, or APLIB_ERROR on error |
Compute required size of workmem buffer used by aP_pack() for compressing input_size bytes of data.
The current code always returns 640k (640*1024).
Parameters: |
|
---|---|
Returns: | required length of work buffer |
Compute maximum possible compressed size when compressing input_size bytes of incompressible data.
The current code returns (input_size + (input_size / 8) + 64).
Parameters: |
|
---|---|
Returns: | maximum possible size of compressed data |
Wrapper function for aP_pack(), which adds a header to the compressed data containing the length of the original data, and CRC32 checksums of the original and compressed data.
Parameters: |
|
---|---|
Returns: | length of compressed data, or APLIB_ERROR on error |
See also
/* allocate workmem and destination memory */
char *workmem = malloc(aP_workmem_size(length));
char *compressed = malloc(aP_max_packed_size(length));
/* compress data[] to compressed[] */
size_t outlength = aPsafe_pack(data, compressed, length, workmem, NULL, NULL);
/* if APLIB_ERROR is returned, and error occured */
if (outlength == APLIB_ERROR) {
printf("An error occured!\n");
}
else {
printf("Compressed %u bytes to %u bytes\n", length, outlength);
}