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.
|
© 2004-2022 Adobe Systems Incorporated. All rights reserved.
Thu Mar 21 2024, 10:06 AM GMT