Class
ZipArchive
public class ZipArchive
An read-only archive.
Relationships
Nested Types
ZipArchive.AddFileFlagsA set of flags to be used with
ZipArchive.addFile.ZipArchive.EntryCollectionA collection of read-only entries in the archive.
ZipArchive.FDOpenFlagsA set of flags to be used with
ZipArchive.init(fd:flags:).ZipArchive.LocateFlagsA set of flags to be used with
ZipArchivename-based APIs:locate,statandopen.ZipArchive.OpenFlagsA set of flags to be used with
ZipArchive.init.ZipArchive.VersionA version of the archive.
Subclasses
ZipMutableArchiveAn mutable archive.
Initializers
init(path:flags:)
public convenience init(path: String, flags: OpenFlags = []) throws
Opens the zip archive specified by path and sets up an instance, used to manipulate the archive.
Parameters
| Name | Type | Description |
|---|---|---|
| path | String |
path to open |
| flags | OpenFlags |
open flags, defaults to |
init(url:flags:)
public convenience init(url: URL, flags: OpenFlags = []) throws
Opens the zip archive specified by URL and sets up an instance, used to manipulate the archive.
Parameters
| Name | Type | Description |
|---|---|---|
| url | URL |
URL to open |
| flags | OpenFlags |
open flags, defaults to |
init(source:flags:)
public convenience init(source: ZipSource, flags: OpenFlags = []) throws
Opens a zip archive encapsulated by the ZipSource and sets up an instance, used to manipulate the archive.
Parameters
| Name | Type | Description |
|---|---|---|
| source | ZipSource |
source to open |
| flags | OpenFlags |
open flags, defaults to |
init(fd:flags:)
public convenience init(fd: Int32, flags: FDOpenFlags = []) throws
The zip archive specified by the open file descriptor fd is opened and an instance, used to manipulate
the archive, is comfigured. In contrast to other initializers, the archive can only be opened in read-only mode.
The fd argument may not be used any longer after calling ZipArchive.init(fd:flags:).
Upon successful completion fd should not be used any longer, nor passed to close(2).
In the error case, fd remains unchanged.
Parameters
| Name | Type | Description |
|---|---|---|
| fd | Int32 |
file descriptor to use |
| flags | FDOpenFlags |
open flags, defaults to |
Methods
discard()
public func discard()
Closes archive and frees the memory allocated for it. Any changes to the archive are not written to disk and discarded.
The ZipArchive object is invalidated and must not be used after call to dsicard().
setDefaultPassword(_:)
public func setDefaultPassword(_ password: String?) throws
Sets the default password used when accessing encrypted files. If password is nil, the default password is unset.
If you prefer a different password for single files, pass password to ZipArchive.open or ZipEntry.open instead.
Usually, however, the same password is used for every file in an zip archive.
Parameters
| Name | Type | Description |
|---|---|---|
| password | String? |
the password to be used |
getComment(decodingStrategy:version:)
public func getComment(decodingStrategy: ZipStringDecodingStrategy = .guess, version: Version = .current) throws -> String
Returns the comment for the entire zip archive.
Parameters
| Name | Type | Description |
|---|---|---|
| decodingStrategy | ZipStringDecodingStrategy |
string decoding strategy, defaults to |
| version | Version |
archive version to use, defaults to |
getRawComment(version:)
public func getRawComment(version: Version = .current) throws -> Data
Returns the unmodified archive comment as it is in the ZIP archive.
Parameters
| Name | Type | Description |
|---|---|---|
| version | Version |
archive version to use, defaults to |
getEntryCount(version:)
public func getEntryCount(version: Version = .current) throws -> Int
Returns the number of files in archive.
Parameters
| Name | Type | Description |
|---|---|---|
| version | Version |
archive version to use, defaults to |
getEntry(index:version:)
public func getEntry(index: Int, version: Version = .current) throws -> ZipEntry
Retrieves archive entry by index.
Parameters
| Name | Type | Description |
|---|---|---|
| index | Int |
index of entry to retrieve |
locate(filename:locateFlags:version:)
public func locate(filename: String, locateFlags: LocateFlags = [], version: Version = .current) throws -> ZipEntry
Returns the index of the file named filename in archive. If archive does not contain a file
with that name, an error is thrown.
Parameters
| Name | Type | Description |
|---|---|---|
| filename | String |
entry name to locate |
| locateFlags | LocateFlags |
lookup options, defaults to |
| version | Version |
archive version to use, defaults to |
stat(filename:locateFlags:version:)
public func stat(filename: String, locateFlags: LocateFlags = [], version: Version = .current) throws -> ZipStat
Obtains information about the file named filename in archive.
Parameters
| Name | Type | Description |
|---|---|---|
| filename | String |
entry name |
| locateFlags | LocateFlags |
lookup options, defaults to |
| version | Version |
archive version to use, defaults to |
open(filename:flags:locateFlags:version:password:)
public func open(filename: String, flags: ZipEntry.OpenFlags = [], locateFlags: LocateFlags = [], version: Version = .current, password: String? = nil) throws -> ZipEntryReader
Opens the file named filename in archive using the password given in the password argument.
Parameters
| Name | Type | Description |
|---|---|---|
| filename | String |
entry name to open |
| flags | ZipEntry.OpenFlags |
open flags, defaults to |
| locateFlags | LocateFlags |
lookup options, defaults to |
| version | Version |
archive version to use, defaults to |
| password | String? |
optional password to decrypt the entry |
entries(version:)
public func entries(version: Version = .current) -> EntryCollection
Exposes archive entries as a Swift Collection