Back

CreateZipUtil

JS Py
Hello World
Content:
- Properties
- 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();
}
from native import app

def OnStart():
    name = app.GetAppName()
    file = "/sdcard/" + name + ".zip"

    zip = app.CreateZipUtil()
    zip.Open(file)
    list = zip.List("").split(",")
    app.Alert("\n".join(list))
    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 );
    }
}
from native import app

def OnStart():
    global name, fldr, zip
    name = app.GetAppName()
    fldr = app.GetPath() + "/" + name
    file = "/sdcard/" + name + ".zip"
    app.ShowProgress()

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

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

def AddFolder(zip, name, fldr):
    list = app.ListFolder(fldr, "")
    for i in range(len(list)):
        title = list[i]
        if not app.IsFolder(fldr + "/" + title):
            zip.AddFile(name + "/" + title, fldr + "/" + title)
        else:
            AddFolder(zip, name + "/" + title, fldr + "/" + title)
    Copy     Copy All       Run      

Properties

The following properties are available on the ZipUtil object:

dataObject: { key, value }

Methods

The following methods are available on the ZipUtil object:

Close()
Create( file ) → void
CreateDebugKey( file ) → void
GetType() → String: “ZipUtil”
List( path ) → String: comma “,” separated
Open( file )
Sign( fileIn, fileOut, keyStore, password ) → Boolean
all types
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: args }
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.data
An object for saving individual extra properties.
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