Lhasa
Typedefs | Functions
lha_decoder.h File Reference

Raw LHA data decoder. More...

Typedefs

typedef struct _LHADecoderType LHADecoderType
 Opaque type representing a type of decoder. More...
 
typedef struct _LHADecoder LHADecoder
 Opaque type representing an instance of a decoder. More...
 
typedef size_t(* LHADecoderCallback )(void *buf, size_t buf_len, void *user_data)
 Callback function invoked when a decoder wants to read more compressed data. More...
 
typedef void(* LHADecoderProgressCallback )(unsigned int num_blocks, unsigned int total_blocks, void *callback_data)
 Callback function used for monitoring decode progress. More...
 

Functions

LHADecoderTypelha_decoder_for_name (char *name)
 Get the decoder type for the specified name. More...
 
LHADecoderlha_decoder_new (LHADecoderType *dtype, LHADecoderCallback callback, void *callback_data, size_t stream_length)
 Allocate a new decoder for the specified type. More...
 
void lha_decoder_free (LHADecoder *decoder)
 Free a decoder. More...
 
void lha_decoder_monitor (LHADecoder *decoder, LHADecoderProgressCallback callback, void *callback_data)
 Set a callback function to monitor decode progress. More...
 
size_t lha_decoder_read (LHADecoder *decoder, uint8_t *buf, size_t buf_len)
 Decode (decompress) more data. More...
 
uint16_t lha_decoder_get_crc (LHADecoder *decoder)
 Get the current 16-bit CRC of the decompressed data. More...
 
size_t lha_decoder_get_length (LHADecoder *decoder)
 Get the count of the number of bytes decoded. More...
 

Detailed Description

Raw LHA data decoder.

This file defines the interface to the decompression code, which can be used to decompress the raw compressed data from an LZH file.

Implementations of the various compression algorithms used in LZH archives are provided - these are represented by the LHADecoderType structure, and can be retrieved using the lha_decoder_for_name function. One of these can then be passed to the lha_decoder_new function to create a LHADecoder structure and decompress the data.

Typedef Documentation

typedef struct _LHADecoder LHADecoder

Opaque type representing an instance of a decoder.

This is a decoder structure being used to decompress a stream of compressed data. Instantiated using the lha_decoder_new function and freed using the lha_decoder_free function.

typedef size_t(* LHADecoderCallback)(void *buf, size_t buf_len, void *user_data)

Callback function invoked when a decoder wants to read more compressed data.

Parameters
bufPointer to the buffer in which to store the data.
buf_lenSize of the buffer, in bytes.
user_dataExtra pointer to pass to the decoder.
Returns
Number of bytes read.
typedef void(* LHADecoderProgressCallback)(unsigned int num_blocks, unsigned int total_blocks, void *callback_data)

Callback function used for monitoring decode progress.

The callback is invoked for every block processed (block size depends on decode algorithm).

Parameters
num_blocksNumber of blocks processed so far.
total_blocksTotal number of blocks to process. callback_data Extra user-specified data passed to the callback.
typedef struct _LHADecoderType LHADecoderType

Opaque type representing a type of decoder.

This is an implementation of the decompression code for one of the algorithms used in LZH archive files. Pointers to these structures are retrieved by using the lha_decoder_for_name function.

Function Documentation

LHADecoderType* lha_decoder_for_name ( char *  name)

Get the decoder type for the specified name.

Parameters
nameString identifying the decoder type, for example, "-lh1-".
Returns
Pointer to the decoder type, or NULL if there is no decoder type for the specified name.
void lha_decoder_free ( LHADecoder decoder)

Free a decoder.

Parameters
decoderThe decoder to free.
uint16_t lha_decoder_get_crc ( LHADecoder decoder)

Get the current 16-bit CRC of the decompressed data.

This should be called at the end of decompression to check that the data was extracted correctly, and the value compared against the CRC from the file header.

Parameters
decoderThe decoder.
Returns
16-bit CRC of the data decoded so far.
size_t lha_decoder_get_length ( LHADecoder decoder)

Get the count of the number of bytes decoded.

This should be called at the end of decompression, and the value compared against the file length from the file header.

Parameters
decoderThe decoder.
Returns
The number of decoded bytes.
void lha_decoder_monitor ( LHADecoder decoder,
LHADecoderProgressCallback  callback,
void *  callback_data 
)

Set a callback function to monitor decode progress.

Parameters
decoderThe decoder.
callbackCallback function to monitor decode progress.
callback_dataExtra data to pass to the decoder.
LHADecoder* lha_decoder_new ( LHADecoderType dtype,
LHADecoderCallback  callback,
void *  callback_data,
size_t  stream_length 
)

Allocate a new decoder for the specified type.

Parameters
dtypeThe decoder type.
callbackCallback function for the decoder to call to read more compressed data.
callback_dataExtra data to pass to the callback function.
stream_lengthLength of the uncompressed data, in bytes. When this point is reached, decompression will stop.
Returns
Pointer to the new decoder, or NULL for failure.
size_t lha_decoder_read ( LHADecoder decoder,
uint8_t *  buf,
size_t  buf_len 
)

Decode (decompress) more data.

Parameters
decoderThe decoder.
bufPointer to buffer to store decompressed data.
buf_lenSize of the buffer, in bytes.
Returns
Number of bytes decompressed.