| 1 | --[[------------------------------------------------------------------------ |
| 2 | zlib.lua |
| 3 | support code for zlib library version 1.2.1 |
| 4 | usage lua -lzlib ... |
| 5 | |
| 6 | Author: Tiago Dionizio ([email protected]) |
| 7 | $Id: zlib.lua,v 1.3 2004/07/22 19:11:55 tngd Exp $ |
| 8 | --]]------------------------------------------------------------------------ |
| 9 | |
| 10 | --[[ Exports --------------------------------------------------------------- |
| 11 | |
| 12 | ds = deflate stream |
| 13 | is = inflate stream |
| 14 | int = number (integer) |
| 15 | * = (any type) |
| 16 | |
| 17 | [...] represent optional parameters that may be omited or nil, in wich case |
| 18 | will be replaced by their default values |
| 19 | |
| 20 | -- zlib constants -- |
| 21 | |
| 22 | int zlib.XXXX |
| 23 | |
| 24 | -- zlib functions -- |
| 25 | |
| 26 | string zlib.version() |
| 27 | int zlib.compile_flags() |
| 28 | int zlib.adler32(int adler, string buf) |
| 29 | int zlib.crc32(int crc, string buf) |
| 30 | |
| 31 | string zlib.compress(string buf [, int level] [, int method] [, int windowBits] [, int memLevel] [, int strategy]) |
| 32 | string zlib.uncompress(string buf [, int windowBits]) |
| 33 | |
| 34 | ds zlib.deflate_init([int level] [, int method] [, int windowBits] [, int memLevel] [, int strategy]) |
| 35 | is zlib.inflate_init([int windowBits]) |
| 36 | |
| 37 | -- deflate stream methods -- |
| 38 | |
| 39 | int ds:adler() |
| 40 | int ds:data_type() |
| 41 | int ds:total_in() |
| 42 | int ds:total_out() |
| 43 | int, int df:process(string [, int flush]) |
| 44 | void ds:done() |
| 45 | void ds:callback(function callback, * userdata) |
| 46 | int ds:set_dictionary(string dictionary) |
| 47 | ds [,int] ds:clone() |
| 48 | int ds:reset() |
| 49 | int ds:params(int level, int strategy) |
| 50 | int ds:prime(int bits, int value) |
| 51 | |
| 52 | -- inflate stream methods -- |
| 53 | |
| 54 | int is:adler() |
| 55 | int is:data_type() |
| 56 | int is:total_in() |
| 57 | int is:total_out() |
| 58 | int, int if:process(string [, int flush]) |
| 59 | void if:done() |
| 60 | void is:callback([function callback] [, * userdata]) |
| 61 | void is:dictionary([function callback] [, * userdata]) |
| 62 | int is:set_dictionary(string dictionary) |
| 63 | is [,int] is:clone() |
| 64 | int is:reset() |
| 65 | int, int is:sync(string buf) |
| 66 | |
| 67 | -- callbacks -- |
| 68 | void callback(string buf, * userdata) |
| 69 | void dictionary(* userdata) |
| 70 | |
| 71 | -- general description -- |
| 72 | most functions/methods correspond to the original function in the zlib |
| 73 | library, the main differences are: |
| 74 | |
| 75 | zlib.XXXX constants correspond to the Z_XXXX constants defined in the |
| 76 | zlib library |
| 77 | |
| 78 | when (de)compressing blocks, the generated output is sent to the callback |
| 79 | function, this is done to prevent passing too much meaningful result values |
| 80 | from the process method |
| 81 | |
| 82 | deflate/inflate zlib functions are interfaced through the process method |
| 83 | |
| 84 | ds:params may invoke the output callback |
| 85 | |
| 86 | process method returns the error value and the number of input bytes |
| 87 | processed |
| 88 | |
| 89 | clone method returns a copy of the stream (also copies callbacks) and |
| 90 | returns a new stream object or nil plus an error code |
| 91 | |
| 92 | dictionary callback is not strictly necessary, but may avoid extra process |
| 93 | calls if used, only needed when compressed stream also used a custom |
| 94 | dictionary. when using it you must call is:set_dictionary as needed, if not |
| 95 | you will have to watch the return code for zlib. |
| 96 | |
| 97 | is:sync returns an error code and the number of input bytes processed |
| 98 | |
| 99 | |
| 100 | ** for more information please refer to zlib.h ** |
| 101 | --]]------------------------------------------------------------------------ |
| 102 | |
| 103 | require('requirelib') |
| 104 | |
| 105 | requirelib('lzlib', 'luaopen_zlib', true) |