zip.compress()

Type Function
Library zip.*
Return value none
Revision Release 2022.3683
Keywords zip, compress
See also zip.uncompress()

Overview

Creates or adds files to a zip archive.

Syntax

zip.compress( options )
options (required)

Table. A table of options for the function call — see the next section for details.

Options Reference

zipFile (required)

String. The zip file to compress files to.

zipBaseDir (required)

Constant. The base directory containing the zip archive.

srcBaseDir (required)

Constant. The base directory containing the files to add to the zip archive.

srcFiles (required)

Array. A table specifying a set of file names to compress into the archive.

password (optional)

String. An optional password for the zip file, using standard Zip 2.0 encryption (WinZip AES encryption is currently not supported).

listener (required)

Listener. The listener function invoked at the end of the operation.

Example

local zip = require( "plugin.zip" ) 

local function zipListener( event )

    if ( event.isError ) then
        print( "Error!" )
    else
        print ( event["type"] )  --> compress
        print ( event.response[1] )  --> space.jpg
        print ( event.response[2] )  --> space1.jpg
        print ( event.response[3] )  --> space2.jpg
    end
end

-- Attempts to compress files in the "srcFiles" parameter to "test.zip"
local zipOptions = { 
    zipFile = "test.zip",
    zipBaseDir = system.DocumentsDirectory,
    srcBaseDir = system.ResourceDirectory,
    srcFiles = { "space.jpg", "space1.jpg", "space2.jpg" },
    listener = zipListener
}
zip.compress( zipOptions )