compression.gzip(file)
The gzip() function compress a file using the GZIP file format specification.
Parameters
file
A string or a File instance, representing the file to be compressed.
Return value
Returns a temporary File instance that represent the compressed file.Example
local compression = require "compression"
if #arg == 0 then
error("error: no input file")
end
-- open a file and compress it to a temporary file
local file = sys.File(arg[1])
local gzipped_file = compression.gzip(file)
-- output the size of the uncompressed and compressed file
print("File size : "..file.size)
print("Gzipped file : "..gzipped_file.size)
-- moves the temporary file to the current directory and rename it
gzipped_file:move(file.name:gsub(file.extension, ".gz"))