gzip
gzip is a file format that wraps a DEFLATE stream with a header (file name, comment, time) and a CRC-32 checksum with the size of the original data.
Produces and consumes gzip streams compatible with the gzip tool, Content-Encoding: gzip and zlib's gzopen / inflateInit2.
Classes & types
class
gzip.Compressor
The gzip stream compressor object.
class
gzip.Decompressor
The gzip stream decompressor object.
type
gzip.Header
The header of the gzip member, returned by gzip.decompress.
type
gzip.Options
Options of gzip.compress, every field is optional.
Functions
gzip.compress | Compresses a string into a gzip stream. |
gzip.decompress | Decompresses a gzip stream. |
#gzip.compress
function gzip.compress(raw_data: string, options?: gzip.Options): string
Compresses a string into a gzip stream.
Parameters
| Name | Type | Description |
|---|---|---|
raw_data | string | The string to compress. |
optionsoptional | gzip.Options | The compression options. |
Returns
| Type | Name | Description |
|---|---|---|
string | compressed_data | The compressed string. |
#gzip.decompress
function gzip.decompress(compressed_data: string, start_position?: integer): string, integer, gzip.Header
Decompresses a gzip stream.
Concatenated gzip members are decompressed into one string, like the gzip tool does, data after the last member that is not another gzip member is left unread.
Throws an error on malformed or truncated data, or if the checksum or the size does not match; call via pcall() when processing untrusted input.
Parameters
| Name | Type | Description |
|---|---|---|
compressed_data | string | The gzip stream to decompress. |
start_positionoptional | integer | The position of the stream in the string, 1 by default. |
Returns
| Type | Name | Description |
|---|---|---|
string | decompressed_data | The decompressed string. |
integer | end_position | The position of the first byte after the stream. |
gzip.Header | header | The header of the first member. |