| Language version: | ActionScript 3.0
|
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);
entries:Vector.<ZipEntry> [read-only]
| Language version: | ActionScript 3.0
|
The entries within this zip archive.
Implementation
public function get entries():Vector.<ZipEntry>
public function ZipArchive()
| Language version: | ActionScript 3.0
|
Creates a new, empty zip archive to which new entries can be added.
public function addFilesAsync(folder:File, recurse:Boolean = true, compress:Boolean = true, includeFolderEntries:Boolean = false, followLinks:Boolean = false):void
| Language version: | ActionScript 3.0
|
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.
|
public static function createFromFolder(folder:File, recurse:Boolean = true, compress:Boolean = true, includeFolderEntries:Boolean = false, followLinks:Boolean = false):ZipArchive
| Language version: | ActionScript 3.0
|
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.
|
public function extractFiles(folder:File):uint
| Language version: | ActionScript 3.0
|
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.
|
public function extractFilesAsync(folder:File):void
| Language version: | ActionScript 3.0
|
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.
|
public function findEntry(entry:String):ZipEntry
| Language version: | ActionScript 3.0
|
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.
|
public static function load(file:File):ZipArchive
| Language version: | ActionScript 3.0
|
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.
|
public static function loadFromByteArray(data:ByteArray):ZipArchive
| Language version: | ActionScript 3.0
|
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.
|
public function removeEntry(entry:String):Boolean
| Language version: | ActionScript 3.0
|
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.
|
public function save(file:File):uint
| Language version: | ActionScript 3.0
|
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.
|
public function saveToByteArray(bytes:ByteArray):uint
| Language version: | ActionScript 3.0
|
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.
|
Event object type: flash.events.Event
Event.type property = flash.events.Event.COMPLETE
| Language version: | ActionScript 3.0
|
| Runtime version: | AIR 51.0
|
Dispatched when an asynchronous zip/unzip operation has completed.
The Event.COMPLETE constant defines the value of the type property of a complete event object.
This event has the following properties:
| Property | Value |
bubbles | false |
cancelable | false; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event
object with an event listener. |
target | The network object that has completed loading.
|
Event object type: flash.events.ProgressEvent
ProgressEvent.type property = flash.events.ProgressEvent.PROGRESS
| Language version: | ActionScript 3.0
|
| Runtime version: | AIR 51.0
|
Dispatched during an asynchronous zip/unzip operation.
Defines the value of the type property of a progress event object.
This event has the following properties:
| Property | Value |
bubbles | false |
bytesLoaded | The number of items or bytes loaded at the time the listener processes the event. |
bytesTotal | The total number of items or bytes that ultimately will be loaded if the loading process succeeds. |
cancelable | false; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event
object with an event listener. |
target | The object reporting progress. |
See also
© 2004-2022 Adobe Systems Incorporated. All rights reserved.
Sat Jan 11 2025, 8:30 AM GMT