For more information about how to use Archive API, see File Archiving Guide.
Since: 2.4
typedef (DOMString or File) FileReference;
Since: 2.4
enum ArchiveCompressionLevel {"STORE", "FAST", "NORMAL", "BEST"};
Since: 2.4
[NoInterfaceObject] interface ArchiveManagerObject {
readonly attribute ArchiveManager archive;
};
Tizen implements ArchiveManagerObject;
Since: 2.4
The tizen.archive object allows access to the Archive API.
dictionary ArchiveFileOptions {
boolean overwrite;
};
Since: 2.4
The default value is false
See description of the mode argument of the open() method.
Since: 2.4
dictionary ArchiveFileEntryOptions {
DOMString destination;
boolean stripSourceDirectory;
ArchiveCompressionLevel compressionLevel;
};
Since: 2.4
Since: 2.4
Remark : If destination is not set, then the root directory of archive will be used (equivalent to destination = "").
The virtual root is always removed. To omit all the remaining directory names, set stripSourceDirectory to true.
Source file name | Target file name when destination is "mypackage" | |
---|---|---|
stripSourceDirectory: true | stripSourceDirectory: false | |
documents/tizen/archive/example/test.js | mypackage/test.js | mypackage/tizen/archive/example/test.js |
wgt-private/test/js/main.js | mypackage/main.js | mypackage/test/js/main.js |
downloads/test.c | mypackage/test.c | mypackage/test.c |
Since: 2.4
Remark : The default value is false.
Since: 2.4
Remark : The default compression level is NORMAL.
[NoInterfaceObject] interface ArchiveManager {
long open(FileReference file,
FileMode mode,
ArchiveFileSuccessCallback onsuccess,
optional ErrorCallback? onerror,
optional ArchiveFileOptions? options) raises(WebAPIException);
void abort(long operationIdentifier) raises(WebAPIException);
};
Since: 2.4
open
long open(FileReference file, FileMode mode, ArchiveFileSuccessCallback onsuccess, optional ErrorCallback? onerror, optional ArchiveFileOptions? options);
Since: 2.4
The errorCallback is launched with these error types:
Use mode depending on which operation are intended:
Mode | Description |
---|---|
r | Use this mode for extracting or getting information about the contents of an archive file. file must exist. If the file does not exist, onerror will be invoked (NotFoundError). When an archive file is opened in this mode, add() will not be available. (IOError will be thrown.) |
w | Use this mode to create an archive file and add files to the archive file. If file does not exist, it will be created. If file exists and the overwrite option is true, the existing file will be overwritten with empty archive. If file exists and the overwrite option is false, onerror callback will be invoked (InvalidModificationError). When an archive file is opened in this mode, getEntries(), getEntryByName(), and extractAll() are not available. (IOError will be thrown.) |
rw | Use this mode for archive zipping/unzipping. If file does not exist, it will be created. If file exists and the overwrite option is true, the existing file will be overwritten with an empty archive. If file exists and the overwrite option is false, the existing contents are preserved. Both adding and extracting will be available. |
a | Use this mode to add new files to an archive file. If file does not exist, it will be created. If file exists, then the previous contents of the archive file are preserved and new files can be added to the archive file. In this mode, getEntries(), getEntryByName(), and extractAll() are not available. (IOError will be thrown.) |
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Return value:
long Task ID which can be used to cancel the operation with abort()Exceptions:
with error type TypeMismatchError, if parameter type does not match.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
function successCallback(archive) {
console.log("Success, can now read from archive " + archive);
}
function errorCallback(error) {
console.log(error);
}
tizen.archive.open("downloads/some_archive.zip", "r", successCallback, errorCallback);
abort
void abort(long operationIdentifier);
Since: 2.4
Parameters:
Exceptions:
with error type UnknownError, if any error occurs.
Code example:
function openSuccess(archive) {
operationId = archive.extractAll("downloads/extracted");
tizen.archive.abort(operationId);
}
tizen.archive.open("downloads/some_archive.zip", "r", openSuccess);
interface ArchiveFile {
readonly attribute FileMode mode;
readonly attribute unsigned long long? decompressedSize;
long add(FileReference sourceFile,
optional SuccessCallback? onsuccess,
optional ErrorCallback? onerror,
optional ArchiveFileProgressCallback? onprogress,
optional ArchiveFileEntryOptions? options) raises(WebAPIException);
long extractAll(FileReference destinationDirectory,
optional SuccessCallback? onsuccess,
optional ErrorCallback? onerror,
optional ArchiveFileProgressCallback? onprogress,
optional boolean? overwrite) raises(WebAPIException);
long getEntries(ArchiveFileEntryArraySuccessCallback onsuccess,
optional ErrorCallback? onerror) raises(WebAPIException);
long getEntryByName(DOMString name,
ArchiveFileEntrySuccessCallback onsuccess,
optional ErrorCallback? onerror) raises(WebAPIException);
void close() raises(WebAPIException);
};
Since: 2.4
Since: 2.4
The size is null until the archive is opened.
Since: 2.4
add
long add(FileReference sourceFile, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror, optional ArchiveFileProgressCallback? onprogress, optional ArchiveFileEntryOptions? options);
Since: 2.4
If sourceFile refers to a directory, the directory and its content will be added to ArchiveFile.
The errorCallback is launched with these error types:
Name stored for new entries is constructed from sourceFile according to the stripSourceDirectory and destination options. Names are constructed as follows:
source file | destination | stripSourceDirectory | resulting entry name |
---|---|---|---|
documents/subdir/second/justName.ext | (empty) | false | subdir/second/justName.ext |
documents/subdir/second/justName.ext | (empty) | true | justName.ext |
documents/subdir/justName.ext | "report3" | false | report3/subdir/justName.ext |
documents/subdir/justName.ext | "report3" | true | report3/justName.ext |
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Return value:
long Task ID which can be used to cancel the operation with abort()Exceptions:
with error type TypeMismatchError, if parameter is of the wrong type.
with error type InvalidStateError, if ArchiveFile is not open.
with error type InvalidAccessError, if the file mode is "r".
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
function errorCallback(error) {
console.log(error);
}
function successCallback() {
console.log("done");
}
function progressCallback(opId, val, name) {
console.log("opId: " + opId + " with progress val: " + val);
}
function createSuccess(archive) {
archive.add("downloads/file.txt", successCallback, errorCallback, progressCallback);
}
tizen.archive.open("downloads/new_archive.zip", "w", createSuccess);
extractAll
long extractAll(FileReference destinationDirectory, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror, optional ArchiveFileProgressCallback? onprogress, optional boolean? overwrite);
Since: 2.4
All extracted files will be located in the given directory.
The overwrite attribute determines whether extracted files can overwrite existing files.
The errorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Return value:
long Task ID which can be used to cancel the operation with abort()Exceptions:
with error type TypeMismatchError, if parameter is of the wrong type.
with error type InvalidStateError, if ArchiveFile is not open.
with error type InvalidAccessError, if the file mode is "w" or "a".
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
function errorCallback(error) {
console.log(error);
}
function successCallback() {
console.log("done");
}
function progressCallback(opId, val, name) {
console.log("extracting operation (: " + opId + ") is in progress (" + (val * 100).toFixed(1) + "%)");
}
function openSuccess(archive) {
archive.extractAll("music", successCallback, errorCallback, progressCallback);
}
tizen.archive.open("downloads/some_archive.zip", "r", openSuccess);
getEntries
long getEntries(ArchiveFileEntryArraySuccessCallback onsuccess, optional ErrorCallback? onerror);
Since: 2.4
The errorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Parameters:
Return value:
long Task ID which can be used to cancel the operation with abort()Exceptions:
with error type TypeMismatchError, if parameter is of the wrong type.
with error type InvalidStateError, if ArchiveFile is not open.
with error type InvalidAccessError, if the file mode is "w" or "a".
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
function errorCallback(error) {
console.log(error);
}
function getEntriesSuccess(entries) {
console.log("Entries length: " + entries.length);
for (var i=0; i < entries.length; i++) {
console.log(entries[i].name);
}
}
function openSuccess(archive) {
archive.getEntries(getEntriesSuccess, errorCallback);
}
tizen.archive.open("downloads/some_archive.zip", "r", openSuccess, errorCallback);
getEntryByName
long getEntryByName(DOMString name, ArchiveFileEntrySuccessCallback onsuccess, optional ErrorCallback? onerror);
Since: 2.4
The errorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Parameters:
Return value:
long Task ID which can be used to cancel the operation with abort()Exceptions:
with error type TypeMismatchError, if parameter is of the wrong type.
with error type InvalidStateError, if ArchiveFile is not opened.
with error type InvalidAccessError, if the file mode is "w" or "a".
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
function errorCallback(error) {
console.log(error);
}
function getEntrySuccess(entry) {
console.log("Entry: " + entry.name + " size: " + entry.size);
}
function openSuccess(archive) {
archive.getEntryByName("arch/my_file.txt", getEntrySuccess, errorCallback);
}
tizen.archive.open("downloads/some_archive.zip", "r", openSuccess);
close
void close();
Since: 2.4
Call this method when the archive file is not used any more. Once you call this method, the archive file object will not be available and any further operation attempt results in an InvalidStateError.
Calling close() on an archive file object which is already closed does not raise any exception.
Exceptions:
with error type UnknownError, if any other error occurs.
interface ArchiveFileEntry {
readonly attribute DOMString name;
readonly attribute unsigned long long size;
readonly attribute unsigned long long? compressedSize;
readonly attribute Date modified;
long extract(FileReference destinationDirectory,
optional SuccessCallback? onsuccess,
optional ErrorCallback? onerror,
optional ArchiveFileProgressCallback? onprogress,
optional boolean? stripName,
optional boolean? overwrite) raises(WebAPIException);
};
Since: 2.4
Since: 2.4
If the ArchiveFileEntry member is a folder, the attribute value will be the sum of sizes of all files in this directory.
Since: 2.4
If ArchiveFileEntry member is a folder, the attribute will be sum of the sizes of all files in this directory.
Until a new entry is added to the archive, the compressedSize is null
Since: 2.4
Since: 2.4
extract
long extract(FileReference destinationDirectory, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror, optional ArchiveFileProgressCallback? onprogress, optional boolean? stripName, optional boolean? overwrite);
Since: 2.4
The errorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Return value:
long Task ID which can be used to cancel the operation with abort()Exceptions:
with error type TypeMismatchError, if parameter is of the wrong type.
with error type InvalidValuesError, if directory parameter does not represent a directory.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
function errorCallback(error) {
console.log(error);
}
function extractSuccessCallback() {
console.log("done");
}
function getEntrySuccess(entry) {
entry.extract("downloads/extract", extractSuccessCallback, errorCallback);
}
function openSuccess(archive) {
archive.getEntryByName("my_file.txt", getEntrySuccess, errorCallback);
}
tizen.archive.open("downloads/some_archive.zip", "r", openSuccess, errorCallback);
[Callback=FunctionOnly, NoInterfaceObject] interface ArchiveFileSuccessCallback {
void onsuccess(ArchiveFile archive);
};
Since: 2.4
onsuccess
void onsuccess(ArchiveFile archive);
Since: 2.4
Parameters:
[Callback=FunctionOnly, NoInterfaceObject] interface ArchiveFileEntrySuccessCallback {
void onsuccess(ArchiveFileEntry entry);
};
Since: 2.4
onsuccess
void onsuccess(ArchiveFileEntry entry);
Since: 2.4
Parameters:
[Callback=FunctionOnly, NoInterfaceObject] interface ArchiveFileEntryArraySuccessCallback {
void onsuccess(ArchiveFileEntry[] entries);
};
Since: 2.4
onsuccess
void onsuccess(ArchiveFileEntry[] entries);
Since: 2.4
Parameters:
[Callback=FunctionOnly, NoInterfaceObject] interface ArchiveFileProgressCallback {
void onprogress(long operationIdentifier, double value, DOMString filename);
};
Since: 2.4
onprogress
void onprogress(long operationIdentifier, double value, DOMString filename);
Since: 2.4
Parameters:
module Archive {
typedef (DOMString or File) FileReference;
enum ArchiveCompressionLevel {"STORE", "FAST", "NORMAL", "BEST"};
[NoInterfaceObject] interface ArchiveManagerObject {
readonly attribute ArchiveManager archive;
};
Tizen implements ArchiveManagerObject;
dictionary ArchiveFileOptions {
boolean overwrite;
};
dictionary ArchiveFileEntryOptions {
DOMString destination;
boolean stripSourceDirectory;
ArchiveCompressionLevel compressionLevel;
};
[NoInterfaceObject] interface ArchiveManager {
long open(FileReference file,
FileMode mode,
ArchiveFileSuccessCallback onsuccess,
optional ErrorCallback? onerror,
optional ArchiveFileOptions? options) raises(WebAPIException);
void abort(long operationIdentifier) raises(WebAPIException);
};
interface ArchiveFile {
readonly attribute FileMode mode;
readonly attribute unsigned long long? decompressedSize;
long add(FileReference sourceFile,
optional SuccessCallback? onsuccess,
optional ErrorCallback? onerror,
optional ArchiveFileProgressCallback? onprogress,
optional ArchiveFileEntryOptions? options) raises(WebAPIException);
long extractAll(FileReference destinationDirectory,
optional SuccessCallback? onsuccess,
optional ErrorCallback? onerror,
optional ArchiveFileProgressCallback? onprogress,
optional boolean? overwrite) raises(WebAPIException);
long getEntries(ArchiveFileEntryArraySuccessCallback onsuccess,
optional ErrorCallback? onerror) raises(WebAPIException);
long getEntryByName(DOMString name,
ArchiveFileEntrySuccessCallback onsuccess,
optional ErrorCallback? onerror) raises(WebAPIException);
void close() raises(WebAPIException);
};
interface ArchiveFileEntry {
readonly attribute DOMString name;
readonly attribute unsigned long long size;
readonly attribute unsigned long long? compressedSize;
readonly attribute Date modified;
long extract(FileReference destinationDirectory,
optional SuccessCallback? onsuccess,
optional ErrorCallback? onerror,
optional ArchiveFileProgressCallback? onprogress,
optional boolean? stripName,
optional boolean? overwrite) raises(WebAPIException);
};
[Callback=FunctionOnly, NoInterfaceObject] interface ArchiveFileSuccessCallback {
void onsuccess(ArchiveFile archive);
};
[Callback=FunctionOnly, NoInterfaceObject] interface ArchiveFileEntrySuccessCallback {
void onsuccess(ArchiveFileEntry entry);
};
[Callback=FunctionOnly, NoInterfaceObject] interface ArchiveFileEntryArraySuccessCallback {
void onsuccess(ArchiveFileEntry[] entries);
};
[Callback=FunctionOnly, NoInterfaceObject] interface ArchiveFileProgressCallback {
void onprogress(long operationIdentifier, double value, DOMString filename);
};
};