global zlib
lzlib
, by Tiago Dionizio.
Reference:
- Old location: http://luaforge.net/projects/lzlib/.
- More recent git repo (archived): https://github.com/LuaDist/lzlib
- On luarocks: https://luarocks.org/modules/hisham/lzlib
😱 Types incomplete or incorrect? 🙏 Please contribute!
methods
zlib.version
@return version
- For example 1.2.13
😱 Types incomplete or incorrect? 🙏 Please contribute!
Return the zlib version.
Example:
Reference:
- Corresponding C source code: lzlib.c#L331-L335
zlib.adler32
Return the initial adler32
value.
Call to update the adler32
value, adler32
is the current value, buffer
is passed
to adler32
zlib function and the updated value is returned.
This function is not related to compression but is exported anyway because it might be useful in applications using the compression library.
Example:
local adler = zlib.adler32()
assert(adler == 1.0)
adler = zlib.adler32(adler, 'some text')
assert(adler == 300417946.0)
adler = zlib.adler32(adler, 'some text')
assert(adler == 1144063795.0)
adler = zlib.adler32(adler, 'some text')
assert(adler == 2530937548.0)
Reference:
- Corresponding C source code: lzlib.c#L338-L355
zlib.adler32
Return the initial crc32
(Cyclic Redundancy Check) value.
Call to update the crc32
value, crc32
is the current value, buffer
is passed
to crc32
zlib function and the updated value is returned.
This function is not related to compression but is exported anyway because it might be useful in applications using the compression library.
Example:
local crc = zlib.crc32()
assert(crc == 0.0)
crc = zlib.crc32(crc, 'some text')
assert(crc == 1337638330.0)
crc = zlib.crc32(crc, 'some text')
assert(crc == 2768805016.0)
crc = zlib.crc32(crc, 'some text')
assert(crc == 1021719064.0)
Reference:
- Corresponding C source code: lzlib.c#L358-L375
zlib.compress
function zlib.compress(
buffer: string,
level: integer?,
method: integer?,
window_bits: integer?,
mem_level: sub<integer,default>?,
strategy: sub<integer,default>?
) -> buffer string
level
- The compression level must be -1
(default compression), or between 0
and 9
: 1
gives best speed, 9
gives best compression, 0
gives no compression at all (the input data is simply copied a block at a time).
@param method
- The method parameter is the compression method. It must be 8
(Z_DEFLATED
) in this version of the library.
@param window_bits
- The window_bits
parameter is the base two logarithm of the maximum window size (the size of the history buffer). It should be in the range 8..15
for this version of the library, default 15
.
@param mem_level
- 8
@param strategy
- Z_DEFAULT_STRATEGY
Return a string containing the compressed buffer according to the given parameters.
Example:
local orig = [[
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua.
]]
assert(string.len(zlib.compress(orig)) < string.len(orig))
Reference:
- Corresponding C source code: lzlib.c#L380-L441
zlib.decompress
@param
window_bits
- The window_bits
parameter is the base two logarithm of the maximum window size (the size of the history buffer). It should be in the range 8..15
for this version of the library, default 15
.
Return the decompressed stream after processing the given buffer.
Example:
local uncompressed = 'Lorem ipsum'
local compressed = zlib.compress(uncompressed)
local result = zlib.decompress(compressed)
assert(result == uncompressed)
Reference:
- Corresponding C source code: lzlib.c#L445-L502
zlib.compressobj
function zlib.compressobj(
level: integer?,
method: integer?,
window_bits: integer?,
mem_level: sub<integer,default>?,
strategy: sub<integer,default>?
) -> ZStream {
adlerreset = function,
compress = function,
decompress = function,
flush = function,
close = function,
adler = function,
}
level
- The compression level must be -1
(default compression), or between 0
and 9
: 1
gives best speed, 9
gives best compression, 0
gives no compression at all (the input data is simply copied a block at a time).
@param method
- The method parameter is the compression method. It must be 8
(Z_DEFLATED
) in this version of the library.
@param window_bits
- The window_bits
parameter is the base two logarithm of the maximum window size (the size of the history buffer). It should be in the range 8..15
for this version of the library, default 15
.
@param mem_level
- 8
@param strategy
- Z_DEFAULT_STRATEGY
Return a deflate stream.
In the upstream project this function is called zlib.deflate()
.
Example:
local z_stream = zlib.compressobj(1)
local result = z_stream:compress('test')
assert(type(result) == 'string')
Reference:
- Corresponding C source code: lzlib.c#L156-L173
zlib.decompressobj
function zlib.decompressobj(window_bits: integer?) -> ZStream {
adlerreset = function,
compress = function,
decompress = function,
flush = function,
close = function,
adler = function,
}
window_bits
- The window_bits
parameter is the base two logarithm of the maximum window size (the size of the history buffer). It should be in the range 8..15
for this version of the library, default 15
.
Return an inflate stream.
In the upstream project this function is called zlib.inflate()
.
Example:
local z_stream_com = zlib.compressobj(1)
local compressed = z_stream_com:compress('test')
compressed = compressed .. z_stream_com:flush()
local z_stream_decomp = zlib.decompressobj()
local result = z_stream_decomp:decompress(compressed)
assert(result == 'test')
Reference:
- Corresponding C source code: lzlib.c#L177-L191