zlib.h (2673B)
1 #ifndef ZLIB_H 2 #define ZLIB_H 3 4 #include <stdint.h> 5 #include <stddef.h> 6 7 /* zlib compression methods */ 8 #define Z_DEFLATED 8 9 10 /* Return codes */ 11 #define Z_OK 0 12 #define Z_STREAM_END 1 13 #define Z_NEED_DICT 2 14 #define Z_ERRNO (-1) 15 #define Z_STREAM_ERROR (-2) 16 #define Z_DATA_ERROR (-3) 17 #define Z_MEM_ERROR (-4) 18 #define Z_BUF_ERROR (-5) 19 #define Z_VERSION_ERROR (-6) 20 21 /* Compression levels */ 22 #define Z_NO_COMPRESSION 0 23 #define Z_BEST_SPEED 1 24 #define Z_BEST_COMPRESSION 9 25 #define Z_DEFAULT_COMPRESSION (-1) 26 27 /* Compression strategy */ 28 #define Z_FILTERED 1 29 #define Z_HUFFMAN_ONLY 2 30 #define Z_RLE 3 31 #define Z_FIXED 4 32 #define Z_DEFAULT_STRATEGY 0 33 34 /* Allowed flush values */ 35 #define Z_NO_FLUSH 0 36 #define Z_PARTIAL_FLUSH 1 37 #define Z_SYNC_FLUSH 2 38 #define Z_FULL_FLUSH 3 39 #define Z_FINISH 4 40 #define Z_BLOCK 5 41 #define Z_TREES 6 42 43 /* Data types */ 44 #define Z_BINARY 0 45 #define Z_TEXT 1 46 #define Z_ASCII Z_TEXT 47 #define Z_UNKNOWN 2 48 49 /* zlib stream structure */ 50 typedef struct z_stream_s { 51 const uint8_t *next_in; /* next input byte */ 52 uint32_t avail_in; /* number of bytes available at next_in */ 53 uint32_t total_in; /* total number of input bytes read so far */ 54 55 uint8_t *next_out; /* next output byte will go here */ 56 uint32_t avail_out; /* remaining free space at next_out */ 57 uint32_t total_out; /* total number of bytes output so far */ 58 59 const char *msg; /* last error message, NULL if no error */ 60 void *state; /* not visible by applications */ 61 62 void *opaque; /* private data object passed to zalloc and zfree */ 63 64 int data_type; /* best guess about the data type: binary or text */ 65 uint32_t adler; /* Adler-32 checksum of the uncompressed data */ 66 uint32_t reserved; /* reserved for future use */ 67 } z_stream; 68 69 typedef z_stream *z_streamp; 70 71 /* Basic functions */ 72 int inflateInit(z_streamp strm); 73 int inflate(z_streamp strm, int flush); 74 int inflateEnd(z_streamp strm); 75 76 int deflateInit(z_streamp strm, int level); 77 int deflate(z_streamp strm, int flush); 78 int deflateEnd(z_streamp strm); 79 80 /* Utility functions */ 81 int uncompress(uint8_t *dest, uint32_t *destLen, const uint8_t *source, uint32_t sourceLen); 82 int compress(uint8_t *dest, uint32_t *destLen, const uint8_t *source, uint32_t sourceLen); 83 84 /* Adler-32 checksum */ 85 uint32_t adler32(uint32_t adler, const uint8_t *buf, uint32_t len); 86 87 /* CRC-32 checksum */ 88 uint32_t crc32(uint32_t crc, const uint8_t *buf, uint32_t len); 89 90 #endif /* ZLIB_H */