开源软件名称(OpenSource Name):hamishforbes/lua-ffi-zlib开源软件地址(OpenSource Url):https://github.com/hamishforbes/lua-ffi-zlib开源编程语言(OpenSource Language):Lua 100.0%开源软件介绍(OpenSource Introduction):lua-ffi-zlibA Lua module using LuaJIT's FFI feature to access zlib. Intended primarily for use within OpenResty to allow manipulation of gzip encoded HTTP responses. MethodsBasic methods allowing for simple compression or decompression of gzip data inflateGzip
On error returns deflateGzip
On error returns ExampleReads a file and output the decompressed version. Roughly equivalent to running local table_insert = table.insert
local table_concat = table.concat
local zlib = require('lib.ffi-zlib')
local f = io.open(arg[1], "rb")
local out_f = io.open(arg[2], "w")
local input = function(bufsize)
-- Read the next chunk
local d = f:read(bufsize)
if d == nil then
return nil
end
return d
end
local output_table = {}
local output = function(data)
table_insert(output_table, data)
local ok, err = out_f:write(data)
if not ok then
-- abort decompression when error occurs
return nil, err
end
end
-- Decompress the data
local ok, err = zlib.inflateGzip(input, output)
if not ok then
print(err)
return
end
local decompressed = table_concat(output_table,'')
print(decompressed) Advanced UsageSeveral other methods are available for advanced usage. Some of these map directly to functions in the zlib library itself, see the manual for full details. Others are lower level utility functions. createStream
Returns a z_stream struct, input buffer and output buffer of length initInflate
Calls zlib's inflateInit2 with given stream, defaults to automatic header detection. initDeflate
Calls zlib's deflateInit2 with the given stream.
deflate
This function will loop until all input data is consumed ( inflate
This function will loop until all input data is consumed ( adler
Computes an adler32 checksum for a string, updates an existing checksum if provided crc
Computes an crc32 checksum for a string, updates an existing checksum if provided zlib_err
Returns the string representation of a zlib error code |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论