Back

CreateZipUtil

Hello World
Content:
- Methods

The ZipUtil is handy for creating, editing and extracting zip files.

zip = app.CreateZipUtil( mode ) → app object: ZipUtil

You can even add files or texts to existing zip files, list their contents and extract single files from them.

Example - List Contents

function OnStart()
{
    var name = app.GetAppName();
    var file = "/sdcard/" + name + ".zip";

    var zip = app.CreateZipUtil();
    zip.Open( file );
    var list = zip.List("").split(",");
    app.Alert(list.join(",\n"));
    zip.Close();
}
Copy All       Run      

Example - Compress

function OnStart()
{
    var name = app.GetAppName();
    var fldr = app.GetPath() + "/" + name;
    var file = "/sdcard/" + name + ".zip";
    app.ShowProgress();

    var zip = app.CreateZipUtil();
    zip.Create( file );
    AddFolder( zip, name, fldr );
    zip.Close();

    app.HideProgress();
    app.ShowPopup( "saved to " + file );
}

function AddFolder( zip, name, fldr )
{
    var list = app.ListFolder( fldr,"");
    for( var i = 0; i < list.length; i++ )
    {
        var title = list[i];
        if( !app.IsFolder( fldr + "/" + title ) )
            zip.AddFile( name + "/" + title, fldr + "/" + title );
        else
            AddFolder( zip, name + "/" + title, fldr + "/"+title );
    }
}
    Copy     Copy All       Run      

Methods

The following methods are available on the ZipUtil object:

Close()
GetType() → string: “ZipUtil”
List( path ) → string: comma “,” separated
Open( file )
Sign( fileIn, fileOut, keyStore, password ) → boolean
string
string: comma “,” separated
string: path to file or folder ( “/absolute/...” or “relative/...” )
string: zip path
string: path to file or folder ( “/absolute/...” or “relative/...” ): “debug.keystore”
string: path to file or folder ( “/absolute/...” or “relative/...” ): “user.keystore”
string: comma “,” separated: “Launch”, “Debug”
zip.AddFile
Adds a file to the zip relative to the zip root.
zip.AddText
Adds some text to the zip relative to the zip root.
zip.Close
Closes the zip util.
zip.Create
Creates a new zip file.
zip.CreateDebugKey
Creates a Debuk keystore file
zip.CreateKey
Creates a user keystore file
zip.Extract
Extract a single file from the zip to a gived destination.
zip.GetType
Returns the control class name.
zip.List
Returns a list of the files contained in the zip.
zip.Open
Opens an already existing zip file.
zip.Sign
Signs and checks the zip against the keystore file and returns if it is ok.
zip.UpdateManifest
Updates the zip manifest