| 1 | /* |
| 2 | * Header file for my independent implementation of Deflate |
| 3 | * (RFC1951) compression. |
| 4 | */ |
| 5 | |
| 6 | #ifndef DEFLATE_DEFLATE_H |
| 7 | #define DEFLATE_DEFLATE_H |
| 8 | |
| 9 | enum { |
| 10 | DEFLATE_TYPE_BARE, |
| 11 | DEFLATE_TYPE_ZLIB |
| 12 | }; |
| 13 | |
| 14 | /* ---------------------------------------------------------------------- |
| 15 | * Compression functions. Create a compression context with |
| 16 | * deflate_compress_new(); feed it data with repeated calls to |
| 17 | * deflate_compress_data(); destroy it with |
| 18 | * deflate_compress_free(). |
| 19 | */ |
| 20 | |
| 21 | typedef struct deflate_compress_ctx deflate_compress_ctx; |
| 22 | |
| 23 | /* |
| 24 | * Create a new compression context. `type' indicates whether it's |
| 25 | * bare Deflate (as used in, say, zip files) or Zlib (as used in, |
| 26 | * say, PDF). |
| 27 | */ |
| 28 | deflate_compress_ctx *deflate_compress_new(int type); |
| 29 | |
| 30 | /* |
| 31 | * Free a compression context previously allocated by |
| 32 | * deflate_compress_new(). |
| 33 | */ |
| 34 | void deflate_compress_free(deflate_compress_ctx *ctx); |
| 35 | |
| 36 | /* |
| 37 | * Give the compression context some data to compress. The input |
| 38 | * data is passed in `inblock', and has length `inlen'. This |
| 39 | * function may or may not produce some output data; if so, it is |
| 40 | * written to a dynamically allocated chunk of memory, a pointer to |
| 41 | * that memory is stored in `outblock', and the length of output |
| 42 | * data is stored in `outlen'. It is common for no data to be |
| 43 | * output, if the input data has merely been stored in internal |
| 44 | * buffers. |
| 45 | * |
| 46 | * `flushtype' indicates whether you want to force buffered data to |
| 47 | * be output. It can be one of the following values: |
| 48 | * |
| 49 | * - DEFLATE_NO_FLUSH: nothing is output if the compressor would |
| 50 | * rather not. Use this when the best compression is desired |
| 51 | * (i.e. most of the time). |
| 52 | * |
| 53 | * - DEFLATE_SYNC_FLUSH: all the buffered data is output, but the |
| 54 | * compressed data stream remains open and ready to continue |
| 55 | * compressing data. Use this in interactive protocols when a |
| 56 | * single compressed data stream is split across several network |
| 57 | * packets. |
| 58 | * |
| 59 | * - DEFLATE_END_OF_DATA: all the buffered data is output and the |
| 60 | * compressed data stream is cleaned up. Any checksums required |
| 61 | * at the end of the stream are also output. |
| 62 | */ |
| 63 | int deflate_compress_data(deflate_compress_ctx *ctx, |
| 64 | const void *inblock, int inlen, int flushtype, |
| 65 | void **outblock, int *outlen); |
| 66 | |
| 67 | enum { |
| 68 | DEFLATE_NO_FLUSH, |
| 69 | DEFLATE_SYNC_FLUSH, |
| 70 | DEFLATE_END_OF_DATA |
| 71 | }; |
| 72 | |
| 73 | /* ---------------------------------------------------------------------- |
| 74 | * Decompression functions. Create a decompression context with |
| 75 | * deflate_decompress_new(); feed it data with repeated calls to |
| 76 | * deflate_decompress_data(); destroy it with |
| 77 | * deflate_decompress_free(). |
| 78 | */ |
| 79 | |
| 80 | typedef struct deflate_decompress_ctx deflate_decompress_ctx; |
| 81 | |
| 82 | /* |
| 83 | * Create a new decompression context. `type' means the same as it |
| 84 | * does in deflate_compress_new(). |
| 85 | */ |
| 86 | deflate_decompress_ctx *deflate_decompress_new(int type); |
| 87 | |
| 88 | /* |
| 89 | * Free a decompression context previously allocated by |
| 90 | * deflate_decompress_new(). |
| 91 | */ |
| 92 | void deflate_decompress_free(deflate_decompress_ctx *ctx); |
| 93 | |
| 94 | /* |
| 95 | * Give the decompression context some data to decompress. The |
| 96 | * input data is passed in `inblock', and has length `inlen'. This |
| 97 | * function may or may not produce some output data; if so, it is |
| 98 | * written to a dynamically allocated chunk of memory, a pointer to |
| 99 | * that memory is stored in `outblock', and the length of output |
| 100 | * data is stored in `outlen'. |
| 101 | * |
| 102 | * FIXME: error reporting? |
| 103 | */ |
| 104 | int deflate_decompress_data(deflate_decompress_ctx *ctx, |
| 105 | const void *inblock, int inlen, |
| 106 | void **outblock, int *outlen); |
| 107 | |
| 108 | #endif /* DEFLATE_DEFLATE_H */ |