Decompression

aPLib

Decompression

The following is a description of the aPLib decompression functionality.

Decompression Functions

size_t aP_depack(const void *source, void *destination)

Decompress compressed data from source to destination.

The destination buffer must be large enough to hold the decompressed data.

Parameters:
  • source – pointer to compressed data
  • destination – pointer to where decompressed data should be stored
Returns:

length of decompressed data, or APLIB_ERROR on error

Note

This function is not included in the libraries, but is available in src/c/depack.c. aP_depack_asm_fast() can be used instead.

size_t aP_depack_safe(const void *source, size_t srclen, void *destination, size_t dstlen)

Decompress compressed data from source to destination.

This function reads at most srclen bytes from source, and writes at most dstlen bytes to destination. If there is not enough source or destination space, or a decoding error occurs, the function returns APLIB_ERROR.

Parameters:
  • source – pointer to compressed data
  • srclen – size of source buffer in bytes
  • destination – pointer to where decompressed data should be stored
  • dstlen – size of destination buffer in bytes
Returns:

length of decompressed data, or APLIB_ERROR on error

Note

This function is not included in the libraries, but is available in src/c/depacks.c. aP_depack_asm_safe() can be used instead.

size_t aP_depack_asm(const void *source, void *destination)

Decompress compressed data from source to destination.

The destination buffer must be large enough to hold the decompressed data.

Optimised for size.

Parameters:
  • source – pointer to compressed data
  • destination – pointer to where decompressed data should be stored
Returns:

length of decompressed data, or APLIB_ERROR on error

size_t aP_depack_asm_fast(const void *source, void *destination)

Decompress compressed data from source to destination.

The destination buffer must be large enough to hold the decompressed data.

Optimised for speed.

Parameters:
  • source – pointer to compressed data
  • destination – pointer to where decompressed data should be stored
Returns:

length of decompressed data, or APLIB_ERROR on error

size_t aP_depack_asm_safe(const void *source, size_t srclen, void *destination, size_t dstlen)

Decompress compressed data from source to destination.

This function reads at most srclen bytes from source, and writes at most dstlen bytes to destination. If there is not enough source or destination space, or a decoding error occurs, the function returns APLIB_ERROR.

Parameters:
  • source – pointer to compressed data
  • srclen – size of source buffer in bytes
  • destination – pointer to where decompressed data should be stored
  • dstlen – size of destination buffer in bytes
Returns:

length of decompressed data, or APLIB_ERROR on error

See also

aPsafe_depack()

unsigned int aP_crc32(const void *source, size_t length)

Compute CRC32 value of length bytes of data from source.

Parameters:
  • source – pointer to data to process
  • length – size in bytes of data
Returns:

CRC32 value

Safe Wrapper Functions

size_t aPsafe_check(const void *source)

Compute CRC32 of compressed data in source and check it against value stored in header. Return length of decompressed data stored in header.

Parameters:
  • source – compressed data to process
Returns:

length of decompressed data, or APLIB_ERROR on error

size_t aPsafe_get_orig_size(const void *source)

Return length of decompressed data stored in header of compressed data in source.

Parameters:
  • source – compressed data to process
Returns:

length of decompressed data, or APLIB_ERROR on error

size_t aPsafe_depack(const void *source, size_t srclen, void *destination, size_t dstlen)

Wrapper function for aP_depack_asm_safe(), which checks the CRC32 of the compressed data, decompresses, and checks the CRC32 of the decompressed data.

Parameters:
  • source – pointer to compressed data
  • srclen – size of source buffer in bytes
  • destination – pointer to where decompressed data should be stored
  • dstlen – size of destination buffer in bytes
Returns:

length of decompressed data, or APLIB_ERROR on error

Example

/* get original size */
size_t orig_size = aPsafe_get_orig_size(compressed);

/* allocate memory for decompressed data */
char *data = malloc(orig_size);

/* decompress compressed[] to data[] */
size_t outlength = aPsafe_depack(compressed, compressed_size, data, orig_size);

/* check decompressed length */
if (outlength != orig_size) {
        printf("An error occured!\n");
}
else {
        printf("Decompressed %u bytes\n", outlength);
}