Skip to content

global gzip

https://gitlab.lisn.upsaclay.fr/texlive/luatex/-/blob/f52b099f3e01d53dc03b315e1909245c3d5418d3/source/texk/web2c/luatexdir/luazlib/gzip.lua


methods


gzip.open


function gzip.open(
  filename: string,
  mode: string?
)
 ->  GFile?
 -> err string?

Open a file name using gzopen.

Behaviour is identical to the description given in the zlib library.

The mode parameter is as in fopen (rb or wb) but can also include a compression level (wb9) or a strategy: 'f' for filtered data as in wb6f, h for Huffman-only compression as in wb1h, R for run-length encoding as in wb1R, or F for fixed code compression as in wb9F. (See the description of deflateInit2 for more information about the strategy parameter.) T will request transparent writing or appending with no compression and not using the gzip format.

a can be used instead of w to request that the gzip stream that will be written be appended to the file. + will result in an error, since reading and writing to the same gzip file is not supported. The addition of x when writing will create the file exclusively, which fails if the file already exists. On systems that support it, the addition of e when reading or writing will set the flag to close the file on an execve() call.

It returns a new file handle, or, in case of errors, nil plus an error message

Example:

local g_file = gzip.open('test.gz', 'wb9')
assert(g_file)
for i = 1, 10 do
  g_file:write('This is line ' .. i, '\n')
end
g_file:close()

Reference:

gzip.lines


function gzip.lines(filename: string) ->  fun() -> string

Same behaviour as io.lines in the io standard library provided by lua with the aditional feature of working with gzip files. If a normal text file is read it will read it normaly (normal gzopen behaviour).

Example:

for line in gzip.lines('test.gz') do
  print(line)
end

Reference:

@see io.lines

gzip.close


function gzip.close(file: GFile {
    flush = function,
    read = function,
    lines = function,
    seek = function,
    write = function,
    close = function,
}) -> success true

Close the file.

Example:

local g_file = gzip.open('test.gz', 'rb')
assert(g_file)
local success = gzip.close(g_file)
assert(success == true)
-- gzip.close(g_file) -> attempt to use a closed file

Reference:

@see GFile.close