Packageair.utils
Classpublic class ZipArchive
InheritanceZipArchive Inheritance EventDispatcher Inheritance Object

Language version: ActionScript 3.0
Runtime version: AIR 51

The ZipArchive class is used to represent a zipped-up set of files in memory.

It can be created by loading a .zip file, or can be saved out to a .zip file. The entries can be modified and accessed via the ZipEntry class.

Support is only provided for normal (32-bit) zip files without encryption, and with either 'store' or 'deflate' options.

For example:


 var fZip : File = File.documentsDirectory.resolvePath("myZip.zip");

 var zip : ZipArchive = ZipArchive.load(fZip);

 for (var i : uint = 0; i < zip.entries.length; i++)

     trace( zip.entries[i].toString() );

 
or

 var fZip : File = File.documentsDirectory.resolvePath("myZip.zip");

 var zip : ZipArchive = new ZipArchive();

 zip.entries.push( new ZipEntry("file_one.txt", bytes) );

 zip.save(fZip);

 

See also

ZipEntry class


Public Properties
 PropertyDefined by
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  entries : Vector.<ZipEntry>
[read-only] The entries within this zip archive.
ZipArchive
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined by
  
Creates a new, empty zip archive to which new entries can be added.
ZipArchive
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
EventDispatcher
  
addFilesAsync(folder:File, recurse:Boolean = true, compress:Boolean = true, includeFolderEntries:Boolean = false, followLinks:Boolean = false):void
Modifies an existing ZipArchive object by adding all files within a folder.
ZipArchive
  
createFromFolder(folder:File, recurse:Boolean = true, compress:Boolean = true, includeFolderEntries:Boolean = false, followLinks:Boolean = false):ZipArchive
[static] Creates a new ZipArchive object by zipping up all files within a folder.
ZipArchive
 Inherited
Dispatches an event into the event flow.
EventDispatcher
  
Extracts all of the entries from this zip archive onto the file system within the given folder.
ZipArchive
  
Extracts all of the entries from this zip archive onto the file system within the given folder.
ZipArchive
  
Find an entry in the archive using its name.
ZipArchive
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
  
[static] Creates a new ZipArchive object by loading in data from a file.
ZipArchive
  
[static] Creates a new ZipArchive object by loading in data from a byte array.
ZipArchive
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
  
Remove an entry from the archive using its name.
ZipArchive
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
  
save(file:File):uint
Saves a ZipArchive object to a file.
ZipArchive
  
Saves a ZipArchive object to a byte array.
ZipArchive
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Events
 EventSummaryDefined by
 Inherited [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active.EventDispatcher
 Inherited [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive.EventDispatcher
Property detail
entriesproperty
entries:Vector.<ZipEntry>  [read-only]

Language version: ActionScript 3.0
Runtime version: AIR 51

The entries within this zip archive.

Implementation
    public function get entries():Vector.<ZipEntry>
Constructor detail
ZipArchive()constructor
public function ZipArchive()

Language version: ActionScript 3.0
Runtime version: AIR 51

Creates a new, empty zip archive to which new entries can be added.

Method detail
addFilesAsync()method
public function addFilesAsync(folder:File, recurse:Boolean = true, compress:Boolean = true, includeFolderEntries:Boolean = false, followLinks:Boolean = false):void

Language version: ActionScript 3.0
Runtime version: AIR 51

Modifies an existing ZipArchive object by adding all files within a folder.

This may be performed on a new, empty ZipArchive object, or on one that already has a number of entries. Any duplicate entries (in terms of the names) will be overwritten with new entries discovered from this operation.

This operation is asynchronous and is performed mostly in a separate thread, with ProgressEvent events being dispatched whilst the operation is progressing and a Event.COMPLETE event being dispatched once it has finished. During this time, the ZipArchive object cannot be accessed or updated.

Parameters
folder:File — The folder to use to search for all files to add to the zip archive.
 
recurse:Boolean (default = true) — Whether or not to recurse into any subfolders that are found.
 
compress:Boolean (default = true) — Whether or not to compress the files (if false, files are just stored).
 
includeFolderEntries:Boolean (default = false) — Whether or not to include entries in the archive for each folder. This can be used to ensure empty folders are generated when unzipping: otherwise, folders are only created if they contain a file that is in the archive.
 
followLinks:Boolean (default = false) — Whether or not to follow a symbolic link and include the contents of the target file. By default, links are stored as links, but this can cause problems when unzipping on a Windows platform where a link turns into a file that just has contents being the relative path to the target file. If this is set to true, then any links are stored as the contents of the file that is linked to.

Throws
Error — The folder does not exist or another file error occurs within this operation.
createFromFolder()method 
public static function createFromFolder(folder:File, recurse:Boolean = true, compress:Boolean = true, includeFolderEntries:Boolean = false, followLinks:Boolean = false):ZipArchive

Language version: ActionScript 3.0
Runtime version: AIR 51

Creates a new ZipArchive object by zipping up all files within a folder.

Parameters
folder:File — The folder to use to search for all files to add to the zip archive.
 
recurse:Boolean (default = true) — Whether or not to recurse into any subfolders that are found.
 
compress:Boolean (default = true) — Whether or not to compress the files (if false, files are just stored).
 
includeFolderEntries:Boolean (default = false) — Whether or not to include entries in the archive for each folder. This can be used to ensure empty folders are generated when unzipping: otherwise, folders are only created if they contain a file that is in the archive.
 
followLinks:Boolean (default = false) — Whether or not to follow a symbolic link and include the contents of the target file. By default, links are stored as links, but this can cause problems when unzipping on a Windows platform where a link turns into a file that just has contents being the relative path to the target file. If this is set to true, then any links are stored as the contents of the file that is linked to.

Returns
ZipArchive — The ZipArchive object with entries populated from the given folder.

Throws
Error — The folder does not exist or another file error occurs within this operation.
extractFiles()method 
public function extractFiles(folder:File):uint

Language version: ActionScript 3.0
Runtime version: AIR 51

Extracts all of the entries from this zip archive onto the file system within the given folder.

Parameters
folder:File — The folder into which to create the unzipped files.

Returns
uint — The number of files extracted.

Throws
Error — The folder does not exist or another file error occurs within this operation.
extractFilesAsync()method 
public function extractFilesAsync(folder:File):void

Language version: ActionScript 3.0
Runtime version: AIR 51

Extracts all of the entries from this zip archive onto the file system within the given folder.

This operation is asynchronous and is performed mostly in a separate thread, with ProgressEvent events being dispatched whilst the operation is progressing and a Event.COMPLETE event being dispatched once it has finished. During this time, the ZipArchive object cannot be accessed or updated.

Parameters
folder:File — The folder into which to create the unzipped files.

Throws
Error — The folder does not exist or another file error occurs within this operation.
findEntry()method 
public function findEntry(entry:String):ZipEntry

Language version: ActionScript 3.0
Runtime version: AIR 51

Find an entry in the archive using its name.

Parameters
entry:String — Relative path/filename for the entry to find.

Returns
ZipEntry — The ZipEntry object for this path, or null if no such entry was found.
load()method 
public static function load(file:File):ZipArchive

Language version: ActionScript 3.0
Runtime version: AIR 51

Creates a new ZipArchive object by loading in data from a file.

Parameters
file:File — The File object to open and read the zip information from.

Returns
ZipArchive — The ZipArchive object with entries populated from the zip file central directory.

Throws
Error — The file does not exist or cannot be opened for reading; or if the file is not a valid Zip archive.
loadFromByteArray()method 
public static function loadFromByteArray(data:ByteArray):ZipArchive

Language version: ActionScript 3.0
Runtime version: AIR 51

Creates a new ZipArchive object by loading in data from a byte array.

Parameters
data:ByteArray — The ByteArray object that contains a valid zip archive.

Returns
ZipArchive — The ZipArchive object with entries populated from the zip central directory.

Throws
Error — If the data is not a valid Zip archive.
removeEntry()method 
public function removeEntry(entry:String):Boolean

Language version: ActionScript 3.0
Runtime version: AIR 51

Remove an entry from the archive using its name.

Parameters
entry:String — Relative path/filename for the entry to remove.

Returns
Boolean — True if the entry was found and removed, false if no such entry was found.
save()method 
public function save(file:File):uint

Language version: ActionScript 3.0
Runtime version: AIR 51

Saves a ZipArchive object to a file.

Parameters
file:File — The File object to save the zip archive to. Any existing file will be overwritten.

Returns
uint — The final size of the zip archive file.

Throws
Error — The file cannot be opened for writing.
saveToByteArray()method 
public function saveToByteArray(bytes:ByteArray):uint

Language version: ActionScript 3.0
Runtime version: AIR 51

Saves a ZipArchive object to a byte array.

Parameters
bytes:ByteArray — The ByteArray object into which to write the zip archive data. Data will be written from the current position into the ByteArray which will be expanded as required to ensure it fits the zip archive content.

Returns
uint — The number of bytes of the zip archive that were written to the byte array.