libdragon
Loading...
Searching...
No Matches
Macros | Functions
lz4_dec_internal.h File Reference

Go to the source code of this file.

Macros

#define LZ4_DECOMPRESS_INPLACE_MARGIN(compressed_size)   (((compressed_size) >> 8) + 32)
 Calculate the margin required for in-place decompression.
 
#define DECOMPRESS_LZ4_STATE_SIZE   176
 Size of the LZ4 decompressor state structure, in bytes.
 

Functions

int decompress_lz4_full_inplace (const uint8_t *src, size_t src_size, uint8_t *dst, size_t dst_size)
 Decompress a block of LZ4 data (mem to mem).
 
void decompress_lz4_init (void *state, int fd, int winsize)
 Initialize the LZ4 decompressor state.
 
ssize_t decompress_lz4_read (void *state, void *buf, size_t len)
 Read decompressed data from the LZ4 stream.
 
void decompress_lz4_reset (void *state)
 Reset the LZ4 decompressor state.
 
void * decompress_lz4_full (const char *fn, FILE *fp, size_t cmp_size, size_t size)
 Decompress a full LZ4 file from a FILE pointer.
 

Detailed Description

Author
Giovanni Bajo giova.nosp@m.nnib.nosp@m.ajo@g.nosp@m.mail.nosp@m..com

Macro Definition Documentation

◆ LZ4_DECOMPRESS_INPLACE_MARGIN

#define LZ4_DECOMPRESS_INPLACE_MARGIN (   compressed_size)    (((compressed_size) >> 8) + 32)

Calculate the margin required for in-place decompression.

It is possible to perform in-place decompression of LZ4 data: to do so, allocate a buffer large enough to hold the decompressed data, plus some margin calculated through this function. Then, read the compressed data at the end of the buffer. Finally, call the decompression function (see below).

Example:

// Allocate a buffer large enough to hold the decompressed data,
// pluse the inplace margin.
int buf_size = decompressed_size + LZ4_DECOMPRESS_INPLACE_MARGIN(compressed_size);
void *buf = malloc(buf_size);
// Read compressed data at the end of the buffer
fread(buf + buf_size - compressed_size, 1, compressed_size, fp);
// Decompress
decompress_lz4_full_mem(
buf + buf_size - compressed_size, compressed_size,
buf, decompressed_size,
false);
#define LZ4_DECOMPRESS_INPLACE_MARGIN(compressed_size)
Calculate the margin required for in-place decompression.
Definition lz4_dec_internal.h:38

Function Documentation

◆ decompress_lz4_full_inplace()

int decompress_lz4_full_inplace ( const uint8_t *  src,
size_t  src_size,
uint8_t *  dst,
size_t  dst_size 
)

Decompress a block of LZ4 data (mem to mem).

This function run a LZ4 decompressor on a block of data, from memory to memory.

LZ4 is much faster than PI DMA. To benefit even more from this, it is possible to actually run this function in parallel with the DMA transfer, "racing" with it. If called with dma_race set to true, the function will assume that the source buffer is currently being DMAed into memory, and will throttle itself to never read past the current DMA position.

In addition to this, it is possible to in-place decompress a block of data. See LZ4_DECOMPRESS_INPLACE_MARGIN for more information.

Parameters
srcPointer to source buffer (compressed data)
src_sizeSize of the compressed data in bytes
dstPointer to destination buffer (decompressed data)
dst_sizeSize of the destination buffer in bytes
Returns
int Number of bytes decompressed, or -1 on error.

◆ decompress_lz4_init()

void decompress_lz4_init ( void *  state,
int  fd,
int  winsize 
)

Initialize the LZ4 decompressor state.

Parameters
statePointer to the decompressor state buffer.
fdFile descriptor to read compressed data from.
winsizeWindow size for the decompressor.

◆ decompress_lz4_read()

ssize_t decompress_lz4_read ( void *  state,
void *  buf,
size_t  len 
)

Read decompressed data from the LZ4 stream.

Parameters
statePointer to the decompressor state buffer.
bufBuffer to store decompressed data.
lenNumber of bytes to read.
Returns
Number of bytes read, or -1 on error.

◆ decompress_lz4_reset()

void decompress_lz4_reset ( void *  state)

Reset the LZ4 decompressor state.

Parameters
statePointer to the decompressor state buffer.

◆ decompress_lz4_full()

void * decompress_lz4_full ( const char *  fn,
FILE *  fp,
size_t  cmp_size,
size_t  size 
)

Decompress a full LZ4 file from a FILE pointer.

Parameters
fnFilename (for error messages).
fpFILE pointer to read compressed data from.
cmp_sizeSize of the compressed data.
sizeSize of the decompressed data.
Returns
Pointer to the decompressed data buffer, or NULL on error.