The @zip module contains functions and classes for manipulating
Zip files
and compressing data.
Functions
:shrink(data)
#
Shrink (compress) arbitrary byte data.
Parameters
Return
-
a string containing the compressed data
:expand(data)
#
Expand (uncompress) previously compressed data.
Parameters
-
data
—
a string containing the compressed data
Return
-
a string of uncompressed data
@writer Methods
:new(path)
#
Create object for writing zip files.
Parameters
-
path
—
the path of the zip file to be written
Return
:add_file(src,dst)
#
Add file to zip.
Parameters
-
src
—
the path of the file to add
-
dst
—
the new path of the file within the zip
(optional, default is to use src)
:add_data(data,dst)
#
Add data as file to zip.
Parameters
-
data
—
the file contents
-
dst
—
the path of the file within the zip
:add_folder(path,glob)
#
Add entire folder to zip.
Parameters
-
path
—
the path of the folder to add
-
glob
—
only files matching glob will be added
(optional, default is '*', which matches all files)
Notes
If the folder path is "some/folder", the path within the zip will just be "folder".
@reader Methods
:new(path)
#
Create object for reading zip files.
Parameters
-
path
—
the path of the zip file to be read
Return
:items()
#
Get the list of items within this zip.
Return
-
an array of items, see notes for details
Notes
Each item is like:
{
name : string,
is_folder : boolean,
modified : number (timestamp; seconds since Unix epoch),
size : number (bytes)
}
This is the same output format as os.dir().
Example
#print all files within zip
z = zip.reader('test.zip')
for item,z.items()
print item.name
:get_data(n)
#
Get uncompressed data of file within zip.
Parameters
-
n
—
the index of the file within items()
Return
-
a string containing the uncompressed bytes of the file
Extract file to current directory.
Parameters
-
n
—
the index of the file within items()
Notes
Subdirectories will be created in current directory as necessary.
Extract all files to current directory.
Notes
Subdirectories will be created in current directory as necessary.