]> mj.ucw.cz Git - libucw.git/blob - ucw/lizard.h
Libucw: Update path parameter handling of URL to current RFC (2396).
[libucw.git] / ucw / lizard.h
1 /*
2  *      LiZaRd -- Fast compression method based on Lempel-Ziv 77
3  *
4  *      (c) 2004, Robert Spalek <robert@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _UCW_LIZARD_H
11 #define _UCW_LIZARD_H
12
13 #define LIZARD_NEEDS_CHARS      8
14   /* The compression routine needs input buffer 8 characters longer, because it
15    * does not check the input bounds all the time.  */
16 #define LIZARD_MAX_MULTIPLY     23./22
17 #define LIZARD_MAX_ADD          4
18   /* In the worst case, the compressed file will not be longer than its
19    * original length * 23/22 + 4.
20    *
21    * The additive constant is for EOF and the header of the file.
22    *
23    * The multiplicative constant comes from 19-byte incompressible string
24    * followed by a 3-sequence that can be compressed into 2-byte link.  This
25    * breaks the copy-mode and it needs to be restarted with a new header.  The
26    * total length is 2(header) + 19(string) + 2(link) = 23.
27    */
28
29 /* lizard.c */
30 int lizard_compress(const byte *in, uns in_len, byte *out);
31 int lizard_decompress(const byte *in, byte *out);
32
33 /* lizard-safe.c */
34 struct lizard_buffer;
35
36 struct lizard_buffer *lizard_alloc(void);
37 void lizard_free(struct lizard_buffer *buf);
38 byte *lizard_decompress_safe(const byte *in, struct lizard_buffer *buf, uns expected_length);
39
40 /* adler32.c */
41 uns update_adler32(uns adler, const byte *ptr, uns len);
42
43 static inline uns
44 adler32(const byte *buf, uns len)
45 {
46   return update_adler32(1, buf, len);
47 }
48
49 #endif