Сжатие данных без потерь
作者
#ifndef PURE_DEFLATE_H
#define PURE_DEFLATE_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef PD_WINDOW
#define PD_WINDOW 4096u
#endif
#if PD_WINDOW < 256 || PD_WINDOW > 32768 || (PD_WINDOW & (PD_WINDOW-1))
#error PD_WINDOW must be a power of two from 256 to 32768
#endif
typedef enum { PD_OK=0, PD_ARGUMENT, PD_OUTPUT_FULL, PD_TRUNCATED, PD_DATA } pd_status;
typedef struct { uint32_t head[4096], prev[PD_WINDOW]; } pd_deflate_workspace;
typedef struct { uint16_t count[16], symbol[288]; } pd_huffman;
typedef struct { pd_huffman lit, dist, code; uint8_t lengths[320]; } pd_inflate_workspace;
/* Returns 0 on size overflow. Workspaces and src/dst must be disjoint.
* No allocation, global mutable state, I/O or floating-point arithmetic.
* On failure *written=0, but dst may contain partial output. */
size_t pd_deflate_bound(size_t input_size);
pd_status pd_deflate(const uint8_t *src, size_t n, uint8_t *dst, size_t capacity,
size_t *written, pd_deflate_workspace *work);
/* Raw RFC1951 only; supports stored/fixed/dynamic blocks; rejects trailing bytes.
* Caller must cap output according to its protocol; no checksum is present. */
pd_status pd_inflate(const uint8_t *src, size_t n, uint8_t *dst, size_t capacity,
size_t *written, pd_inflate_workspace *work);
/* Byte shuffle for 8-byte elements. Not an IEEE754 conversion. Buffers disjoint. */
pd_status pd_shuffle8(const uint8_t *src, uint8_t *dst, size_t n);
pd_status pd_unshuffle8(const uint8_t *src, uint8_t *dst, size_t n);
#ifdef __cplusplus
}
#endif
#endif