blob: b7b1a197517606dd215c5e7495a790dc6c170e28 [file] [log] [blame]
rsccfa37a72004-04-10 18:53:55 +00001.TH FLATE 3
2.SH NAME
3deflateinit, deflate, deflatezlib, deflateblock, deflatezlibblock, inflateinit, inflate, inflatezlib, inflateblock, inflatezlibblock, flateerr, mkcrctab, blockcrc, adler32 \- deflate compression
4.SH SYNOPSIS
5.B #include <u.h>
6.br
7.B #include <libc.h>
8.br
9.B #include <flate.h>
10.PP
rscc8b63422005-01-13 04:49:19 +000011.ta \w'\fLulongmm'u +\w'\fL 'u
rsccfa37a72004-04-10 18:53:55 +000012.PP
13.B
14int deflateinit(void)
15.PP
16.B
17int deflate(void *wr, int (*w)(void*,void*,int),
18.br
19.B
rscc8b63422005-01-13 04:49:19 +000020 void *rr, int (*r)(void*,void*,int),
rsccfa37a72004-04-10 18:53:55 +000021.br
22.B
rscc8b63422005-01-13 04:49:19 +000023 int level, int debug)
rsccfa37a72004-04-10 18:53:55 +000024.PP
25.B
26int deflatezlib(void *wr, int (*w)(void*,void*,int),
27.br
28.B
rscc8b63422005-01-13 04:49:19 +000029 void *rr, int (*r)(void*,void*,int),
rsccfa37a72004-04-10 18:53:55 +000030.br
31.B
rscc8b63422005-01-13 04:49:19 +000032 int level, int debug)
rsccfa37a72004-04-10 18:53:55 +000033.PP
34.B
35int deflateblock(uchar *dst, int dsize,
36.br
37.B
rscc8b63422005-01-13 04:49:19 +000038 uchar *src, int ssize,
rsccfa37a72004-04-10 18:53:55 +000039.br
40.B
rscc8b63422005-01-13 04:49:19 +000041 int level, int debug)
rsccfa37a72004-04-10 18:53:55 +000042.PP
43.B
44int deflatezlibblock(uchar *dst, int dsize,
45.br
46.B
rscc8b63422005-01-13 04:49:19 +000047 uchar *src, int ssize,
rsccfa37a72004-04-10 18:53:55 +000048.br
49.B
rscc8b63422005-01-13 04:49:19 +000050 int level, int debug)
rsccfa37a72004-04-10 18:53:55 +000051.PP
52.B
53int inflateinit(void)
54.PP
55.B
56int inflate(void *wr, int (*w)(void*, void*, int),
57.br
58.B
rscc8b63422005-01-13 04:49:19 +000059 void *getr, int (*get)(void*))
rsccfa37a72004-04-10 18:53:55 +000060.PP
61.B
62int inflatezlib(void *wr, int (*w)(void*, void*, int),
63.br
64.B
rscc8b63422005-01-13 04:49:19 +000065 void *getr, int (*get)(void*))
rsccfa37a72004-04-10 18:53:55 +000066.PP
67.B
68int inflateblock(uchar *dst, int dsize,
69.br
70.B
rscc8b63422005-01-13 04:49:19 +000071 uchar *src, int ssize)
rsccfa37a72004-04-10 18:53:55 +000072.PP
73.B
74int inflatezlibblock(uchar *dst, int dsize,
75.br
76.B
rscc8b63422005-01-13 04:49:19 +000077 uchar *src, int ssize)
rsccfa37a72004-04-10 18:53:55 +000078.PP
79.B
80char *flateerr(int error)
81.PP
82.B
83ulong *mkcrctab(ulong poly)
84.PP
85.B
86ulong blockcrc(ulong *tab, ulong crc, void *buf, int n)
87.PP
88.B
89ulong adler32(ulong adler, void *buf, int n)
90.SH DESCRIPTION
91These routines compress and decompress data using the deflate compression algorithm,
92which is used for most gzip, zip, and zlib files.
93.PP
94.I Deflate
95compresses input data retrieved by calls to
96.I r
97with arguments
98.IR rr ,
99an input buffer, and a count of bytes to read.
100.I R
101should return the number of bytes read;
102end of input is signaled by returning zero, an input error by
103returning a negative number.
104The compressed output is written to
105.I w
106with arguments
107.IR wr ,
108the output data, and the number of bytes to write.
109.I W
110should return the number of bytes written;
111writing fewer than the requested number of bytes is an error.
112.I Level
113indicates the amount of computation deflate should do while compressing the data.
114Higher
115.I levels
116usually take more time and produce smaller outputs.
117Valid values are 1 to 9, inclusive; 6 is a good compromise.
118If
119.I debug
120is non-zero, cryptic debugging information is produced on standard error.
121.PP
122.I Inflate
123reverses the process, converting compressed data into uncompressed output.
124Input is retrieved one byte at a time by calling
125.I get
126with the argument
127.IR getr .
128End of input of signaled by returning a negative value.
129The uncompressed output is written to
130.IR w ,
131which has the same interface as for
132.IR deflate .
133.PP
134.I
135Deflateblock
136and
137.I inflateblock
138operate on blocks of memory but are otherwise similar to
139.I deflate
140and
141.IR inflate .
142.PP
143The zlib functions are similar, but operate on files with a zlib header and trailer.
144.PP
145.I Deflateinit
146or
147.I inflateinit
148must be called once before any call to the corresponding routines.
149.PP
150If the above routines fail,
151they return a negative number indicating the problem.
152The possible values are
153.IR FlateNoMem ,
154.IR FlateInputFail ,
155.IR FlateOutputFail ,
156.IR FlateCorrupted ,
157and
158.IR FlateInternal .
159.I Flateerr
160converts the number into a printable message.
161.I FlateOk
162is defined to be zero,
163the successful return value for
164.IR deflateinit ,
165.IR deflate ,
166.IR deflatezlib ,
167.IR inflateinit ,
168.IR inflate ,
169and
170.IR inflatezlib .
171The block functions return the number of bytes produced when they succeed.
172.PP
173.I Mkcrctab
174allocates
175(using
rscbf8a59f2004-04-11 03:42:27 +0000176.IR malloc (3)),
rsccfa37a72004-04-10 18:53:55 +0000177initializes, and returns a table for rapid computation of 32 bit CRC values using the polynomial
178.IR poly .
179.I Blockcrc
180uses
181.IR tab ,
182a table returned by
183.IR mkcrctab ,
184to update
185.I crc
186for the
187.I n
188bytes of data in
189.IR buf ,
190and returns the new value.
191.I Crc
192should initially be zero.
193.I Blockcrc
194pre-conditions and post-conditions
195.I crc
196by ones complementation.
197.PP
198.I Adler32
199updates the Adler 32-bit checksum of the
200.I n
201butes of data in
202.IR buf.
203The initial value of
204.I adler
205(that is, its value after seeing zero bytes) should be 1.
206.SH SOURCE
rscc3674de2005-01-11 17:37:33 +0000207.B \*9/src/libflate