FLATE(3)
π NAME π
okay so this is the FLATE(3) page from the Library Functions Manual β deflate compression edition, and she is iconic π
. The whole squad is: deflateinit, deflate, deflatezlib, deflateblock, deflatezlibblock, inflateinit, inflate, inflatezlib, inflateblock, inflatezlibblock, flateerr, mkcrctab, blockcrc, adler32 β deflate compression.
β¨ SYNOPSIS β¨
here's the exact tea, bestie β no edits, no cap:
#include <u.h>
#include <libc.h>
#include <flate.h>
int deflateinit(void)
int deflate(void *wr, int (*w)(void*,void*,int),
void *rr, int (*r)(void*,void*,int),
int level, int debug)
int deflatezlib(void *wr, int (*w)(void*,void*,int),
void *rr, int (*r)(void*,void*,int),
int level, int debug)
int deflateblock(uchar *dst, int dsize,
uchar *src, int ssize,
int level, int debug)
int deflatezlibblock(uchar *dst, int dsize,
uchar *src, int ssize,
int level, int debug)
int inflateinit(void)
int inflate(void *wr, int (*w)(void*, void*, int),
void *getr, int (*get)(void*))
int inflatezlib(void *wr, int (*w)(void*, void*, int),
void *getr, int (*get)(void*))
int inflateblock(uchar *dst, int dsize,
uchar *src, int ssize)
int inflatezlibblock(uchar *dst, int dsize,
uchar *src, int ssize)
char *flateerr(int error)
ulong *mkcrctab(ulong poly)
ulong blockcrc(ulong *tab, ulong crc, void *buf, int n)
ulong adler32(ulong adler, void *buf, int n)
π DESCRIPTION π
These routines compress and decompress data using the deflate compression algorithm, which is used for most gzip, zip, and zlib files. No cap.
deflate is the compressor. It pulls input data by calling your r function with rr, an input buffer, and a count of bytes to read. Your r should return the number of bytes read; end of input is signaled by returning zero, and an input error is signaled by returning a negative number. The compressed output is written to w with wr, the output data, and the number of bytes to write. Your w should return the number of bytes written; writing fewer than the requested number of bytes is an error. level is how much computation deflate should do while compressing β higher levels usually take more time and produce smaller outputs. Valid values are 1 to 9, inclusive; 6 is a good compromise. If debug is non-zero, cryptic debugging information is produced on standard error.
inflate reverses the process, converting compressed data into uncompressed output. Input is retrieved one byte at a time by calling get with the argument getr. End of input is signaled by returning a negative value. The uncompressed output is written to w, which has the same interface as for deflate.
deflateblock and inflateblock operate on blocks of memory but are otherwise similar to deflate and inflate.
The zlib functions are similar, but operate on files with a zlib header and trailer.
deflateinit or inflateinit must be called once before any call to the corresponding routines. periodt.
If the above routines fail, they return a negative number indicating the problem. The possible values are FlateNoMem, FlateInputFail, FlateOutputFail, FlateCorrupted, and FlateInternal. flateerr converts the number into a printable message. FlateOk is defined to be zero β the successful return value for deflateinit, deflate, deflatezlib, inflateinit, inflate, and inflatezlib. The block functions return the number of bytes produced when they succeed.
mkcrctab allocates (using malloc(3)), initializes, and returns a table for rapid computation of 32 bit CRC values using the polynomial poly. blockcrc uses tab, a table returned by mkcrctab, to update crc for the n bytes of data in buf, and returns the new value. crc should initially be zero. blockcrc pre-conditions and post-conditions crc by ones complementation.
adler32 updates the Adler 32-bit checksum of the n butes (that's the page's spelling, bestie π) of data in buf. The initial value of adler (that is, its value after seeing zero bytes) should be 1.
πΈ SOURCE πΈ
/src/libflate is where she lives, and that's the whole FLATE(3) page β signing off, mwah πβ¨
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms