ZXC 1.0.3
High-performance asymmetric lossless compression library
Loading...
Searching...
No Matches
zxc_buffer.h File Reference

One-shot buffer compression and decompression. More...

#include <stddef.h>
#include <stdint.h>
#include "zxc_constants.h"
#include "zxc_export.h"
#include "zxc_opts.h"

Go to the source code of this file.

Data Structures

struct  zxc_frame_info_t
 What a frame's header and footer declare, read without decoding. More...

Typedefs

typedef struct zxc_cctx_s zxc_cctx
 Opaque reusable compression context (see zxc_create_cctx).
typedef struct zxc_dctx_s zxc_dctx
 Opaque reusable decompression context (see zxc_create_dctx).

Functions

int zxc_min_level (void)
 Minimum supported compression level.
int zxc_max_level (void)
 Maximum supported compression level.
int zxc_default_level (void)
 Default compression level.
const char * zxc_version_string (void)
 Library version string, "MAJOR.MINOR.PATCH".
unsigned zxc_version_number (void)
 Library version as one integer, ZXC_VERSION_NUMBER of the loaded library.
const char * zxc_version_codename (void)
 Release code name of the loaded library, ZXC_VERSION_CODENAME.
size_t zxc_compress_bound (const size_t input_size)
 Maximum compressed size for an input of input_size bytes.
int64_t zxc_compress (const void *src, const size_t src_size, void *dst, const size_t dst_capacity, int level)
 Compresses a buffer into a complete ZXC archive, at level.
int64_t zxc_decompress (const void *src, const size_t src_size, void *dst, const size_t dst_capacity)
 Decompresses a complete ZXC archive.
size_t zxc_decompress_inplace_bound (const void *src, const size_t src_size)
 Buffer size required for an in-place decompression of src.
int64_t zxc_decompress_inplace (void *buffer, const size_t buffer_capacity, const size_t comp_size)
 Decompresses inside a single caller-owned buffer.
uint64_t zxc_get_decompressed_size (const void *src, const size_t src_size)
 Reads the original size from the archive footers, without decoding.
uint32_t zxc_get_dict_id (const void *src, size_t src_size)
 Reads the dictionary ID an archive requires, from its header.
int zxc_requires_dict (const void *src, size_t src_size)
 Tells whether an archive requires a dictionary, from its header.
int zxc_get_frame_info (const void *src, size_t src_size, zxc_frame_info_t *info, size_t info_size)
 Reads a frame's header and footer, without decoding.
int zxc_get_last_frame_info (const void *src, size_t src_size, zxc_frame_info_t *info, size_t info_size)
 Reads the last frame of src, without decoding.
size_t zxc_frame_info_size (void)
 Returns sizeof(zxc_frame_info_t) as compiled into the library.
size_t zxc_compress_block_bound (size_t input_size)
 Maximum compressed size for a single block.
size_t zxc_decompress_block_bound (const size_t uncompressed_size)
 Minimum dst_capacity zxc_decompress_block() needs for a block of uncompressed_size bytes.
int64_t zxc_compress_block (zxc_cctx *cctx, const void *src, size_t src_size, void *dst, size_t dst_capacity)
 Compresses a single block without file framing.
int64_t zxc_decompress_block (zxc_dctx *dctx, const void *src, size_t src_size, void *dst, size_t dst_capacity)
 Decompresses a single block produced by zxc_compress_block().
int64_t zxc_decompress_block_safe (zxc_dctx *dctx, const void *src, const size_t src_size, void *dst, const size_t dst_capacity)
 Decompresses a single block into an exactly-sized destination.
size_t zxc_estimate_cctx_size (size_t src_size, int level)
 Estimates peak compression memory for a given block size and level.
zxc_cctx * zxc_create_cctx (void)
 Creates a reusable compression context, every parameter at its default.
void zxc_free_cctx (zxc_cctx *cctx)
 Frees a compression context and its resources.
int zxc_cctx_set_param (zxc_cctx *cctx, zxc_cparam_t param, int64_t value)
 Sets one parameter on cctx; 0 restores its default.
int zxc_cctx_get_param (const zxc_cctx *cctx, zxc_cparam_t param, int64_t *value)
 Reads one parameter of cctx.
int zxc_cctx_set_dict (zxc_cctx *cctx, const void *dict, size_t dict_size, const void *dict_huf)
 Attaches a pre-trained dictionary to cctx; a NULL dict detaches.
int zxc_cctx_set_progress (zxc_cctx *cctx, zxc_progress_callback_t cb, void *user_data)
 Sets the progress callback; NULL cb disables it.
int zxc_cctx_reset (zxc_cctx *cctx)
 Restores every parameter to its default, detaches the dictionary and the callback.
int64_t zxc_compress_cctx (zxc_cctx *cctx, const void *src, size_t src_size, void *dst, size_t dst_capacity)
 Compresses data using a reusable context.
zxc_dctx * zxc_create_dctx (void)
 Creates a reusable decompression context.
void zxc_free_dctx (zxc_dctx *dctx)
 Frees a decompression context and its resources.
int zxc_dctx_set_param (zxc_dctx *dctx, zxc_dparam_t param, int64_t value)
 Sets one parameter on dctx; 0 restores its default.
int zxc_dctx_get_param (const zxc_dctx *dctx, zxc_dparam_t param, int64_t *value)
 Reads one parameter of dctx.
int zxc_dctx_set_dict (zxc_dctx *dctx, const void *dict, size_t dict_size, const void *dict_huf)
 Attaches the dictionary the archives were compressed with; NULL detaches.
int zxc_dctx_set_progress (zxc_dctx *dctx, zxc_progress_callback_t cb, void *user_data)
 Sets the progress callback; NULL cb disables it.
int zxc_dctx_reset (zxc_dctx *dctx)
 Restores every parameter to its default, detaches the dictionary and the callback.
int64_t zxc_decompress_dctx (zxc_dctx *dctx, const void *src, size_t src_size, void *dst, size_t dst_capacity)
 Decompresses data using a reusable context.
int64_t zxc_decompress_inplace_dctx (zxc_dctx *dctx, void *buffer, const size_t buffer_capacity, const size_t comp_size)
 In-place decompression with a caller-supplied context.
size_t zxc_static_cctx_workspace_size (const size_t block_size, const int level)
 Exact size of a static compression workspace.
zxc_cctx * zxc_init_static_cctx (void *workspace, const size_t workspace_size, const size_t block_size, const int level)
 Initialises a compression context inside a caller-supplied workspace.
size_t zxc_static_dctx_workspace_size (const size_t block_size)
 Exact size of a static decompression workspace.
zxc_dctx * zxc_init_static_dctx (void *workspace, const size_t workspace_size, const size_t block_size)
 Initialises a decompression context inside a caller-supplied workspace.

Detailed Description

One-shot buffer compression and decompression.

The simplest way to use ZXC: one input buffer in, one output buffer out. Everything here is single-threaded and blocking.

Typical usage
// Compress, the simple form: one level, every other parameter at its default
size_t bound = zxc_compress_bound(src_size);
void *dst = malloc(bound);
int64_t csize = zxc_compress(src, src_size, dst, bound, ZXC_LEVEL_DEFAULT);
// Decompress
uint64_t orig = zxc_get_decompressed_size(dst, csize);
void *out = malloc(orig);
int64_t dsize = zxc_decompress(dst, csize, out, orig);
// Anything else goes through a configured context (Reusable Context API)
csize = zxc_compress_cctx(cctx, src, src_size, dst, bound);
struct zxc_cctx_s zxc_cctx
Opaque reusable compression context (see zxc_create_cctx).
Definition zxc_buffer.h:370
uint64_t zxc_get_decompressed_size(const void *src, const size_t src_size)
Reads the original size from the archive footers, without decoding.
int64_t zxc_decompress(const void *src, const size_t src_size, void *dst, const size_t dst_capacity)
Decompresses a complete ZXC archive.
size_t zxc_compress_bound(const size_t input_size)
Maximum compressed size for an input of input_size bytes.
int64_t zxc_compress(const void *src, const size_t src_size, void *dst, const size_t dst_capacity, int level)
Compresses a buffer into a complete ZXC archive, at level.
void zxc_free_cctx(zxc_cctx *cctx)
Frees a compression context and its resources.
int64_t zxc_compress_cctx(zxc_cctx *cctx, const void *src, size_t src_size, void *dst, size_t dst_capacity)
Compresses data using a reusable context.
int zxc_cctx_set_param(zxc_cctx *cctx, zxc_cparam_t param, int64_t value)
Sets one parameter on cctx; 0 restores its default.
zxc_cctx * zxc_create_cctx(void)
Creates a reusable compression context, every parameter at its default.
@ ZXC_LEVEL_DEFAULT
Recommended default: better ratio and decode speed than LZ4.
@ ZXC_C_CHECKSUM
1 appends the block checksums and the archive digest; default 0.
Definition zxc_opts.h:66
See also
zxc_stream.h multi-threaded FILE* streaming.
zxc_pstream.h single-threaded push streaming.

Definition in file zxc_buffer.h.