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 ( “/absolute/...” or “relative/...” )
String: path to file or folder ( “/absolute/...” or “relative/...” )
String: zip path
String: path to file ( “/absolute/...” or “relative/...” ): “debug.keystore”
String: path to file ( “/absolute/...” or “relative/...” ): “user.keystore”
String: comma “,” separated: “Launch”, “Debug”
Object: { COMMAND }
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.Batch
Batch method calls to be able to set all object's properties at once.
Note that you need to specify each parameter (use “” or null to leave some out)
Inherited methods can be called by appending an underscore to the function name (ie. txt.Batch({ SetBackColor_: [“red”] })
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