Requires Scripting PRO
The Archive class provides a comprehensive interface for working with archive files (such as ZIP).
It supports reading, creating, updating, and extracting entries from archives, with both asynchronous and synchronous methods.
Archive enables flexible management of compressed archive contents, including:
deflate, none)static openForMode(path: string, accessMode: "update" | "read", options?: { pathEncoding?: Encoding }): ArchiveOpens an archive file.
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string |
The file path of the archive. |
accessMode |
"update" |
"read" |
options.pathEncoding |
Encoding |
Optional. The path encoding used inside the archive (default is "utf-8"). |
Returns:
An Archive object.
Example:
path: stringThe path of the archive file.
Example:
data: Data | nullThe raw data of the archive (if opened from memory).
entries(pathEncoding?: Encoding): ArchiveEntry[]Retrieves the entries in the archive.
Parameters:
pathEncoding: Optional. The encoding to use for decoding entry paths (default is "utf-8").
Returns:
An array of ArchiveEntry objects.
getEntryPaths(encoding?: Encoding): string[]Retrieves the paths of all entries in the archive.
Parameters:
encoding: Optional. The encoding to use for decoding entry paths (default is "utf-8").
Returns: An array of entry paths.
getEntry(path: string): ArchiveEntry | nullRetrieves an entry by its path.
Parameters:
path: The path of the entry to retrieve.
Returns:
The ArchiveEntry object if found; otherwise, null.
contains(path: string): booleanChecks whether the archive contains a specific entry.
Parameters:
path: The path of the entry to check.
Returns:
true if the path exists; otherwise, false.
Example:
addEntry(path: string, toPath: string, options?: { compressionMethod?: "deflate" | "none"; bufferSize?: number }): Promise<void>Adds an existing file to the archive (asynchronously).
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string |
The source file path. |
toPath |
string |
The destination path inside the archive. |
options.compressionMethod |
"deflate" |
"none" |
options.bufferSize |
number |
Buffer size in bytes (default: 16 * 1024). |
Example:
addEntrySync(path: string, toPath: string, options?)Synchronous version of addEntry().
Throws an error if the entry cannot be added.
addFileEntry(path: string, uncompressedSize: number, provider: (offset: number, length: number) => Data, options?): Promise<void>Adds a file entry to the archive using a data provider function (asynchronous).
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string |
The target file path inside the archive. |
uncompressedSize |
number |
The uncompressed file size. |
provider |
(offset: number, length: number) => Data |
A function that provides file data by chunks. |
options.modificationDate |
Date |
Optional modification date. |
options.compressionMethod |
"deflate" |
"none" |
options.bufferSize |
number |
Buffer size in bytes (default: 16 * 1024). |
Example:
addFileEntrySync(...)Synchronous version of addFileEntry().
addDirectoryEntry(path: string, options?): Promise<void>Adds a directory entry to the archive.
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string |
Directory path to add. |
options.modificationDate |
Date |
Optional modification date. |
options.compressionMethod |
"deflate" |
"none" |
options.bufferSize |
number |
Buffer size (default: 16 * 1024). |
Example:
addDirectoryEntrySync(...)Synchronous version of addDirectoryEntry().
removeEntry(path: string, options?): Promise<void>Removes a specific entry from the archive (asynchronously).
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string |
The path of the entry to remove. |
options.bufferSize |
number |
Buffer size (default: 16 * 1024). |
Example:
removeEntrySync(...)Synchronous version of removeEntry().
extract(path: string, consumer: (data: Data) => void, options?): Promise<void>Extracts a specific entry from the archive and provides its data in chunks via a consumer callback (asynchronous).
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string |
The path of the entry to extract. |
consumer |
(data: Data) => void |
A callback to process each data chunk. |
options.bufferSize |
number |
Buffer size (default: 16 * 1024). |
Example:
extractSync(...)Synchronous version of extract().
extractTo(path: string, to: string, options?): Promise<void>Extracts an entry or directory from the archive to a specific file system location (asynchronously).
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string |
Path of the entry inside the archive. |
to |
string |
Target path to extract to. |
options.bufferSize |
number |
Buffer size (default: 16 * 1024). |
options.allowUncontainedSymlinks |
boolean |
Whether to allow uncontained symlinks (default: false). |
Example:
extractToSync(...)Synchronous version of extractTo().
ArchiveEntry represents a single entry (file, directory, or symbolic link) inside an archive.
| Property | Type | Description |
|---|---|---|
path |
string |
The path of the entry. |
type |
"file" |
"directory" |
isCompressed |
boolean |
Whether the entry is compressed. |
compressedSize |
number |
Compressed size in bytes. |
uncompressedSize |
number |
Uncompressed size in bytes. |
fileAttributes |
{ posixPermissions?: number; modificationDate?: Date } |
File attributes. |
Example: