Lhasa: lha_decoder.h File Reference

Lhasa

Loading...
Searching...
No Matches
Typedefs | Functions
lha_decoder.h File Reference

Raw LHA data decoder. More...

## Typedefs
typedef struct _LHADecoderType | LHADecoderType
| Opaque type representing a type of decoder.
typedef struct _LHADecoder | LHADecoder
| Opaque type representing an instance of a decoder.
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.
typedef void(* | LHADecoderProgressCallback) (unsigned int num_blocks, unsigned int total_blocks, void *callback_data)
| Callback function used for monitoring decode progress.

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

## 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

## ◆ LHADecoder

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.

## ◆ LHADecoderCallback

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

  buf | Pointer to the buffer in which to store the data.
  buf_len | Size of the buffer, in bytes.
  user_data | Extra pointer to pass to the decoder.

Returns
  Number of bytes read.

## ◆ LHADecoderProgressCallback

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; the block size that is chosen is arbitrary and depends on the decode algorithm and file size, but you should not make any assumptions about how many bytes are in a block.

Parameters

  num_blocks | Number of blocks processed so far.
  total_blocks | Total number of blocks to process.
  callback_data | Extra user-specified data passed to the callback.

## ◆ LHADecoderType

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

## ◆ lha_decoder_for_name()

const LHADecoderType * lha_decoder_for_name | ( | const char * | name | ) |

Get the decoder type for the specified name.

Parameters

  name | String 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.

## ◆ lha_decoder_free()

void lha_decoder_free | ( | LHADecoder * | decoder | ) |

Free a decoder.

Parameters

  decoder | The decoder to free.

## ◆ lha_decoder_get_crc()

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

  decoder | The decoder.

Returns
  16-bit CRC of the data decoded so far.

## ◆ lha_decoder_get_length()

uint64_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

  decoder | The decoder.

Returns
  The number of decoded bytes.

## ◆ lha_decoder_monitor()

void lha_decoder_monitor | ( | LHADecoder * | decoder,
|  | LHADecoderProgressCallback | callback,
|  | void * | callback_data )

Set a callback function to monitor decode progress.

Parameters

  decoder | The decoder.
  callback | Callback function to monitor decode progress.
  callback_data | Extra data to pass to the decoder.

## ◆ lha_decoder_new()

LHADecoder * lha_decoder_new | ( | const LHADecoderType * | dtype,
|  | LHADecoderCallback | callback,
|  | void * | callback_data,
|  | uint64_t | stream_length )

Allocate a new decoder for the specified type.

Parameters

  dtype | The decoder type.
  callback | Callback function for the decoder to call to read more compressed data.
  callback_data | Extra data to pass to the callback function.
  stream_length | Length of the uncompressed data, in bytes. When this point is reached, decompression will stop.

Returns
  Pointer to the new decoder, or NULL for failure.

## ◆ lha_decoder_read()

size_t lha_decoder_read | ( | LHADecoder * | decoder,
|  | uint8_t * | buf,
|  | size_t | buf_len )

Decode (decompress) more data.

Parameters

  decoder | The decoder.
  buf | Pointer to buffer to store decompressed data.
  buf_len | Size of the buffer, in bytes.

Returns
  Number of bytes decompressed.