Library zlib
Zlib compression and decompression library
From https://github.com/LuaDist/lzlib
Author:
Copyright © The MIT License (MIT); Copyright Tiago Dionizio (tiago.dionizio@gmail.com)
Functions
- adler32 (adler, buffer)
Compute an adler32 checksum
- compress (buffer, level, method, windowBits, memLevel, strategy)
Return a string containing the compressed buffer according to the given parameters.
- crc32 (crc, buffer)
Compute a crc32 checksum
- decompress (buffer, windowBits)
Return the decompressed stream after processing the given buffer.
- deflate (sink, level, method, windowBits, memLevel, strategy, dictionary)
Return a deflate stream.
- deflate_stream:flush (value)
Flush output for deflate streams.
- deflate_stream:write (...)
Write each parameter into the stream
- inflate (source, windowBits, dictionary)
Return an inflate stream.
- inflate_stream:lines ()
Return iterator that returns a line each time it is called, or nil on end of file.
- inflate_stream:read (how)
Read from an inflate stream
- stream:close ()
Close the stream.
- version ()
returns zlib version
Functions
- adler32 (adler, buffer)
-
Compute an adler32 checksum
Without any parameters, returns the initial adler32 value.
Call to update the adler32 value, adler is the current value, buffer is passed to adler32 zlib function and the updated value is returned.
Parameters
- adler
- An integer, the result of a previous call to
adler32
- buffer
- A string, over which to compute the adler32 checksum.
Return value:
The adler32 checksum result. - compress (buffer, level, method, windowBits, memLevel, strategy)
-
Return a string containing the compressed buffer according to the given parameters.
All of the parameters besides buffer are optional. The zlib library sets the default values, which are usually equivalent to
compress(buffer, 6, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY)
Parameters
- buffer
- String to compress
- level
- Optional integer corresponding to compression level, 0-9
- method
- Optional integer corresponding to compression method
- windowBits
- Optional integer, the base-2 logarithm of the maximum window size. Default: 15
- memLevel
- Optional integer corresponding to memory use and therefore speed
- strategy
- Optional integer corresponding to compression strategy
- crc32 (crc, buffer)
-
Compute a crc32 checksum
Without any parameters, returns the initial crc32 value.
Call to update the crc32 value, crc is the current value, buffer is passed to crc32 zlib function and the updated value is returned.
Parameters
- crc
- An integer, the result of a previous call to
crc32
- buffer
- A string, over which to compute the crc32 checksum.
Return value:
The crc32 checksum result. - decompress (buffer, windowBits)
-
Return the decompressed stream after processing the given buffer.
If windowBits is negative, this function decompresses raw deflate data without header.
Parameters
- buffer
- String containing DEFLATE-compressed data
- windowBits
- Optional integer, the base-2 logarithm of the maximum window size. Default: 15
- deflate (sink, level, method, windowBits, memLevel, strategy, dictionary)
-
Return a deflate stream.
This stream is a file-like object that can be used to write compressed (deflated) data to some sink stream. If the sink stream is a table or object, it must have a
write
method. Otherwise, it must be a function that will be called with data to write (e.g.socket.send
).Parameters
- sink
- The location where compressed data will be written
- level
- Optional integer corresponding to compression level, 0-9
- method
- Optional integer corresponding to compression method
- windowBits
- Optional integer, the base-2 logarithm of the maximum window size. Default: 15
- memLevel
- Optional integer corresponding to memory use and therefore speed
- strategy
- Optional integer corresponding to compression strategy
- dictionary
- Optional string corresponding to initial compression dictionary
- deflate_stream:flush (value)
-
Flush output for deflate streams.
Parameters
- value
- One of 'sync', 'full', or 'finish'
Return values:
- True, or false on error
- Error string on error
- deflate_stream:write (...)
-
Write each parameter into the stream
Parameters
- ...
- any number of strings to write
Return values:
- True, or false on error
- Error string on error
- inflate (source, windowBits, dictionary)
-
Return an inflate stream.
This stream is a file-like object that can be used to read decompressed (inflated) data from some source stream. If the source stream is a table or object, it must have a
read
method. Otherwise, it must be a function that will be called to get more compressed data.Parameters
- source
- The location where compressed data will be read from
- windowBits
- Optional integer, the base-2 logarithm of the maximum window size. Default: 15
- dictionary
- Optional string corresponding to initial compression dictionary
Return value:
an inflate stream. - inflate_stream:lines ()
-
Return iterator that returns a line each time it is called, or nil on end of file.
Return value:
An iterator suitable for use withfor
- inflate_stream:read (how)
-
Read from an inflate stream
Parameters
- how
- A number of bytes to read, or "*l" (read until newline), or "*a" (read the whole stream). Default: "*l"
Return value:
The bytes read, or nil on EOF. - stream:close ()
-
Close the stream.
Return values:
- True, or false on error
- An error string
- version ()
-
returns zlib version
Return value:
the zlib version