zip.compress()

Type Function
Library zip.*
Return value none
Revision 2017.3060
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.

listener (required)

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

Example

local zip = require( "plugin.zip" ) 

-- Attempts to compress files in the "filenames" parameter to "test.zip".

local function zipListener( event )

    if ( event.isError ) then
        print( "Error!" )
    else
        print ( "event.name: " .. event.name )
        print ( "event.type: " .. event.type )

        --example response
        --event.response = {
        --[1] = "space.jpg",
        --[2] = "space1.jpg",
        --}
    end
end

local zipOptions = { 
    zipFile = "test.zip",
    zipBaseDir = system.DocumentsDirectory,
    srcBaseDir = system.ResourceDirectory,
    srcFiles = { "space.jpg", "space1.jpg", "space2.jpg" },
    listener = zipListener
}
zip.compress( zipOptions )