# Archive Class Reference



## Scope and provenance

- Product: mobile
- Status: Imported reference snapshot. Import date is not a verification date or guarantee of current release support.
- SDK version: Not declared for this page. Versions in examples must not be assumed current.
- Environment: Page-specific. Confirm the environment host, credentials, and service configuration; do not infer them from another product.
- Source: https://documentation.idmission.com/identity/iOS-SDK-2/Classes/Archive.html
- Imported at: 2026-10-21T17:27:02.187Z
- Canonical page: https://docs.idmission.com/mobile/reference/ios/Classes/Archive
- Agent index: https://docs.idmission.com/llms.txt

---

<a id="archive"></a>

# Archive

```
public final class Archive : Sequence
```

A sequence of uncompressed or compressed ZIP entries.

You use an `Archive` to create, read or update ZIP files. To read an existing ZIP file, you have to pass in an existing file `URL` and `AccessMode.read`:

```
var archiveURL = URL(fileURLWithPath: "/path/file.zip")
var archive = Archive(url: archiveURL, accessMode: .read)
```

An `Archive` is a sequence of entries. You can iterate over an archive using a `for`-`in` loop to get access to individual `Entry` objects:

```
for entry in archive {
    print(entry.path)
}
```

Each `Entry` in an `Archive` is represented by its `path`. You can use `path` to retrieve the corresponding `Entry` from an `Archive` via subscripting:

```
let entry = archive['/path/file.txt']
```

To create a new `Archive`, pass in a non-existing file URL and `AccessMode.create`. To modify an existing `Archive` use `AccessMode.update`:

```
var archiveURL = URL(fileURLWithPath: "/path/file.zip")
var archive = Archive(url: archiveURL, accessMode: .update)
try archive?.addEntry("test.txt", relativeTo: baseURL, compressionMethod: .deflate)
```

- <a id="/s:17IDentitySDK_Swift7ArchiveC0D5ErrorO"></a>

  <a id="//apple_ref/swift/Enum/ArchiveError"></a>

  `ArchiveError`

  An error that occurs during reading, creating or updating a ZIP file.

  [See more](https://docs.idmission.com/markdown/mobile/reference/ios/Classes/Archive/ArchiveError.md)

  <a id="declaration"></a>

  #### Declaration

  Swift

  ```
  public enum ArchiveError : Error
  ```

- <a id="/s:17IDentitySDK_Swift7ArchiveC10AccessModeO"></a>

  <a id="//apple_ref/swift/Enum/AccessMode"></a>

  `AccessMode`

  The access mode for an `Archive`.

  [See more](https://docs.idmission.com/markdown/mobile/reference/ios/Classes/Archive/AccessMode.md)

  <a id="declaration-2"></a>

  #### Declaration

  Swift

  ```
  public enum AccessMode : UInt
  ```

- <a id="/s:17IDentitySDK_Swift7ArchiveC3url10Foundation3URLVvp"></a>

  <a id="//apple_ref/swift/Property/url"></a>

  `url`

  URL of an Archive’s backing file.

  <a id="declaration-3"></a>

  #### Declaration

  Swift

  ```
  public let url: URL
  ```

- <a id="/s:17IDentitySDK_Swift7ArchiveC10accessModeAC06AccessF0Ovp"></a>

  <a id="//apple_ref/swift/Property/accessMode"></a>

  `accessMode`

  Access mode for an archive file.

  <a id="declaration-4"></a>

  #### Declaration

  Swift

  ```
  public let accessMode: AccessMode
  ```

- <a id="/s:17IDentitySDK_Swift7ArchiveC3url10accessMode17preferredEncodingACSg10Foundation3URLV_AC06AccessG0OSSAHE0I0VSgtcfc"></a>

  <a id="//apple_ref/swift/Method/init(url:accessMode:preferredEncoding:)"></a>

  `init(url:accessMode:preferredEncoding:)`

  Initializes a new ZIP `Archive`.

  You can use this initalizer to create new archive files or to read and update existing ones. The `mode` parameter indicates the intended usage of the archive: `.read`, `.create` or `.update`.

  Note

  - The file URL *must* point to an existing file for `AccessMode.read`.
  - The file URL *must* point to a non-existing file for `AccessMode.create`.
  - The file URL *must* point to an existing file for `AccessMode.update`.

  <a id="declaration-5"></a>

  #### Declaration

  Swift

  ```
  public init?(url: URL, accessMode mode: AccessMode, preferredEncoding: String.Encoding? = nil)
  ```

  <a id="parameters"></a>

  #### Parameters

  |                     |                                                                                                                                                                                                                  |
  | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `url`               | File URL to the receivers backing file.                                                                                                                                                                          |
  | `mode`              | Access mode of the receiver.                                                                                                                                                                                     |
  | `preferredEncoding` | Encoding for entry paths. Overrides the encoding specified in the archive. This encoding is only used when *decoding* paths from the receiver. Paths of entries added with `addEntry` are always UTF-8 encoded.  |

  <a id="return-value"></a>

  #### Return Value

  An archive initialized with a backing file at the passed in file URL and the given access mode or `nil` if the following criteria are not met:

- <a id="/s:17IDentitySDK_Swift7ArchiveC4data10accessMode17preferredEncodingACSg10Foundation4DataV_AC06AccessG0OSSAHE0I0VSgtcfc"></a>

  <a id="//apple_ref/swift/Method/init(data:accessMode:preferredEncoding:)"></a>

  `init(data:accessMode:preferredEncoding:)`

  Initializes a new in-memory ZIP `Archive`.

  You can use this initalizer to create new in-memory archive files or to read and update existing ones.

  Note

  - The backing `data` *must* contain a valid ZIP archive for `AccessMode.read` and `AccessMode.update`.
  - The backing `data` *must* be empty (or omitted) for `AccessMode.create`.

  <a id="declaration-6"></a>

  #### Declaration

  Swift

  ```
  public init?(data: Data = Data(), accessMode mode: AccessMode, preferredEncoding: String.Encoding? = nil)
  ```

  <a id="parameters-2"></a>

  #### Parameters

  |                     |                                                                                                                                                                                                                  |
  | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `data`              | `Data` object used as backing for in-memory archives.                                                                                                                                                            |
  | `mode`              | Access mode of the receiver.                                                                                                                                                                                     |
  | `preferredEncoding` | Encoding for entry paths. Overrides the encoding specified in the archive. This encoding is only used when *decoding* paths from the receiver. Paths of entries added with `addEntry` are always UTF-8 encoded.  |

  <a id="return-value-2"></a>

  #### Return Value

  An in-memory archive initialized with passed in backing data.

- <a id="/s:ST12makeIterator0B0QzyF"></a>

  <a id="//apple_ref/swift/Method/makeIterator()"></a>

  `makeIterator()`

  <a id="declaration-7"></a>

  #### Declaration

  Swift

  ```
  public func makeIterator() -> AnyIterator<Entry>
  ```

- <a id="/s:17IDentitySDK_Swift7ArchiveCyAA5EntryVSgSScip"></a>

  <a id="//apple_ref/swift/Method/subscript(_:)"></a>

  `subscript(_:)`

  Retrieve the ZIP `Entry` with the given `path` from the receiver.

  Note

  The ZIP file format specification does not enforce unique paths for entries. Therefore an archive can contain multiple entries with the same path. This method always returns the first `Entry` with the given `path`.

  <a id="declaration-8"></a>

  #### Declaration

  Swift

  ```
  public subscript(path: String) -> Entry? { get }
  ```

  <a id="parameters-3"></a>

  #### Parameters

  |        |                                                              |
  | ------ | ------------------------------------------------------------ |
  | `path` | A relative file path identifying the corresponding `Entry`.  |

  <a id="return-value-3"></a>

  #### Return Value

  An `Entry` with the given `path`. Otherwise, `nil`.

- <a id="/s:17IDentitySDK_Swift7ArchiveC4data10Foundation4DataVSgvp"></a>

  <a id="//apple_ref/swift/Property/data"></a>

  `data`

  Returns a `Data` object containing a representation of the receiver.

  <a id="declaration-9"></a>

  #### Declaration

  Swift

  ```
  public var data: Data? { get }
  ```

- <a id="/s:17IDentitySDK_Swift7ArchiveC25totalUnitCountForRemovingys5Int64VAA5EntryVF"></a>

  <a id="//apple_ref/swift/Method/totalUnitCountForRemoving(_:)"></a>

  `totalUnitCountForRemoving(_:)`

  The number of the work units that have to be performed when removing `entry` from the receiver.

  <a id="declaration-10"></a>

  #### Declaration

  Swift

  ```
  public func totalUnitCountForRemoving(_ entry: Entry) -> Int64
  ```

  <a id="parameters-4"></a>

  #### Parameters

  |         |                                  |
  | ------- | -------------------------------- |
  | `entry` | The entry that will be removed.  |

  <a id="return-value-4"></a>

  #### Return Value

  The number of the work units.

- <a id="/s:17IDentitySDK_Swift7ArchiveC24totalUnitCountForReadingys5Int64VAA5EntryVF"></a>

  <a id="//apple_ref/swift/Method/totalUnitCountForReading(_:)"></a>

  `totalUnitCountForReading(_:)`

  The number of the work units that have to be performed when reading `entry` from the receiver.

  <a id="declaration-11"></a>

  #### Declaration

  Swift

  ```
  public func totalUnitCountForReading(_ entry: Entry) -> Int64
  ```

  <a id="parameters-5"></a>

  #### Parameters

  |         |                               |
  | ------- | ----------------------------- |
  | `entry` | The entry that will be read.  |

  <a id="return-value-5"></a>

  #### Return Value

  The number of the work units.

- <a id="/s:17IDentitySDK_Swift7ArchiveC27totalUnitCountForAddingItem2ats5Int64V10Foundation3URLV_tF"></a>

  <a id="//apple_ref/swift/Method/totalUnitCountForAddingItem(at:)"></a>

  `totalUnitCountForAddingItem(at:)`

  The number of the work units that have to be performed when adding the file at `url` to the receiver.

  <a id="declaration-12"></a>

  #### Declaration

  Swift

  ```
  public func totalUnitCountForAddingItem(at url: URL) -> Int64
  ```

  <a id="parameters-6"></a>

  #### Parameters

  |         |                                  |
  | ------- | -------------------------------- |
  | `entry` | The entry that will be removed.  |

  <a id="return-value-6"></a>

  #### Return Value

  The number of the work units.

- <a id="/s:17IDentitySDK_Swift7ArchiveC7extract_2to10bufferSize9skipCRC328progresss6UInt32VAA5EntryV_10Foundation3URLVSiSbSo10NSProgressCSgtKF"></a>

  <a id="//apple_ref/swift/Method/extract(_:to:bufferSize:skipCRC32:progress:)"></a>

  `extract(_:to:bufferSize:skipCRC32:progress:)`

  Read a ZIP `Entry` from the receiver and write it to `url`.

  Throws

  An error if the destination file cannot be written or the entry contains malformed content.

  <a id="declaration-13"></a>

  #### Declaration

  Swift

  ```
  public func extract(_ entry: Entry, to url: URL, bufferSize: Int = defaultReadChunkSize, skipCRC32: Bool = false,
                      progress: Progress? = nil) throws -> CRC32
  ```

  <a id="parameters-7"></a>

  #### Parameters

  |              |                                                                                  |
  | ------------ | -------------------------------------------------------------------------------- |
  | `entry`      | The ZIP `Entry` to read.                                                         |
  | `url`        | The destination file URL.                                                        |
  | `bufferSize` | The maximum size of the read buffer and the decompression buffer (if needed).    |
  | `skipCRC32`  | Optional flag to skip calculation of the CRC32 checksum to improve performance.  |
  | `progress`   | A progress object that can be used to track or cancel the extract operation.     |

  <a id="return-value-7"></a>

  #### Return Value

  The checksum of the processed content or 0 if the `skipCRC32` flag was set to `true`.

- <a id="/s:17IDentitySDK_Swift7ArchiveC7extract_10bufferSize9skipCRC328progress8consumers6UInt32VAA5EntryV_SiSbSo10NSProgressCSgy10Foundation4DataVKXEtKF"></a>

  <a id="//apple_ref/swift/Method/extract(_:bufferSize:skipCRC32:progress:consumer:)"></a>

  `extract(_:bufferSize:skipCRC32:progress:consumer:)`

  Read a ZIP `Entry` from the receiver and forward its contents to a `Consumer` closure.

  Throws

  An error if the destination file cannot be written or the entry contains malformed content.

  <a id="declaration-14"></a>

  #### Declaration

  Swift

  ```
  public func extract(_ entry: Entry, bufferSize: Int = defaultReadChunkSize, skipCRC32: Bool = false,
                      progress: Progress? = nil, consumer: Consumer) throws -> CRC32
  ```

  <a id="parameters-8"></a>

  #### Parameters

  |              |                                                                                  |
  | ------------ | -------------------------------------------------------------------------------- |
  | `entry`      | The ZIP `Entry` to read.                                                         |
  | `bufferSize` | The maximum size of the read buffer and the decompression buffer (if needed).    |
  | `skipCRC32`  | Optional flag to skip calculation of the CRC32 checksum to improve performance.  |
  | `progress`   | A progress object that can be used to track or cancel the extract operation.     |
  | `consumer`   | A closure that consumes contents of `Entry` as `Data` chunks.                    |

  <a id="return-value-8"></a>

  #### Return Value

  The checksum of the processed content or 0 if the `skipCRC32` flag was set to `true`..

- <a id="/s:17IDentitySDK_Swift7ArchiveC7extract_2to10bufferSize9skipCRC328progresss6UInt32VAA5EntryV_10Foundation3URLVAJSbSo10NSProgressCSgtKF"></a>

  `extract(_:to:bufferSize:skipCRC32:progress:)`

  <a id="declaration-15"></a>

  #### Declaration

  Swift

  ```
  func extract(_ entry: Entry, to url: URL, bufferSize: UInt32, skipCRC32: Bool = false,
               progress: Progress? = nil) throws -> CRC32
  ```

- <a id="/s:17IDentitySDK_Swift7ArchiveC7extract_10bufferSize9skipCRC328progress8consumers6UInt32VAA5EntryV_AJSbSo10NSProgressCSgy10Foundation4DataVKXEtKF"></a>

  `extract(_:bufferSize:skipCRC32:progress:consumer:)`

  <a id="declaration-16"></a>

  #### Declaration

  Swift

  ```
  func extract(_ entry: Entry, bufferSize: UInt32, skipCRC32: Bool = false,
               progress: Progress? = nil, consumer: Consumer) throws -> CRC32
  ```

- <a id="/s:17IDentitySDK_Swift7ArchiveC8addEntry4with10relativeTo17compressionMethod10bufferSize8progressySS_10Foundation3URLVAA011CompressionK0OSiSo10NSProgressCSgtKF"></a>

  <a id="//apple_ref/swift/Method/addEntry(with:relativeTo:compressionMethod:bufferSize:progress:)"></a>

  `addEntry(with:relativeTo:compressionMethod:bufferSize:progress:)`

  Write files, directories or symlinks to the receiver.

  Throws

  An error if the source file cannot be read or the receiver is not writable.

  <a id="declaration-17"></a>

  #### Declaration

  Swift

  ```
  public func addEntry(with path: String, relativeTo baseURL: URL,
                       compressionMethod: CompressionMethod = .none,
                       bufferSize: Int = defaultWriteChunkSize, progress: Progress? = nil) throws
  ```

  <a id="parameters-9"></a>

  #### Parameters

  |                     |                                                                                                                   |
  | ------------------- | ----------------------------------------------------------------------------------------------------------------- |
  | `path`              | The path that is used to identify an `Entry` within the `Archive` file.                                           |
  | `baseURL`           | The base URL of the resource to add. The `baseURL` combined with `path` must form a fully qualified file URL.     |
  | `compressionMethod` | Indicates the `CompressionMethod` that should be applied to `Entry`. By default, no compression will be applied.  |
  | `bufferSize`        | The maximum size of the write buffer and the compression buffer (if needed).                                      |
  | `progress`          | A progress object that can be used to track or cancel the add operation.                                          |

- <a id="/s:17IDentitySDK_Swift7ArchiveC8addEntry4with7fileURL17compressionMethod10bufferSize8progressySS_10Foundation0I0VAA011CompressionK0OSiSo10NSProgressCSgtKF"></a>

  <a id="//apple_ref/swift/Method/addEntry(with:fileURL:compressionMethod:bufferSize:progress:)"></a>

  `addEntry(with:fileURL:compressionMethod:bufferSize:progress:)`

  Write files, directories or symlinks to the receiver.

  Throws

  An error if the source file cannot be read or the receiver is not writable.

  <a id="declaration-18"></a>

  #### Declaration

  Swift

  ```
  public func addEntry(with path: String, fileURL: URL, compressionMethod: CompressionMethod = .none,
                       bufferSize: Int = defaultWriteChunkSize, progress: Progress? = nil) throws
  ```

  <a id="parameters-10"></a>

  #### Parameters

  |                     |                                                                                                                   |
  | ------------------- | ----------------------------------------------------------------------------------------------------------------- |
  | `path`              | The path that is used to identify an `Entry` within the `Archive` file.                                           |
  | `fileURL`           | An absolute file URL referring to the resource to add.                                                            |
  | `compressionMethod` | Indicates the `CompressionMethod` that should be applied to `Entry`. By default, no compression will be applied.  |
  | `bufferSize`        | The maximum size of the write buffer and the compression buffer (if needed).                                      |
  | `progress`          | A progress object that can be used to track or cancel the add operation.                                          |

- <a id="/s:17IDentitySDK_Swift7ArchiveC8addEntry4with4type16uncompressedSize16modificationDate11permissions17compressionMethod06bufferJ08progress8providerySS_AA0F0V0F4TypeOs5Int64V10Foundation0L0Vs6UInt16VSgAA011CompressionO0OSiSo10NSProgressCSgAT4DataVAS_SitKXEtKF"></a>

  <a id="//apple_ref/swift/Method/addEntry(with:type:uncompressedSize:modificationDate:permissions:compressionMethod:bufferSize:progress:provider:)"></a>

  `addEntry(with:type:uncompressedSize:modificationDate:permissions:compressionMethod:bufferSize:progress:provider:)`

  Write files, directories or symlinks to the receiver.

  Throws

  An error if the source data is invalid or the receiver is not writable.

  <a id="declaration-19"></a>

  #### Declaration

  Swift

  ```
  public func addEntry(with path: String, type: Entry.EntryType, uncompressedSize: Int64,
                       modificationDate: Date = Date(), permissions: UInt16? = nil,
                       compressionMethod: CompressionMethod = .none, bufferSize: Int = defaultWriteChunkSize,
                       progress: Progress? = nil, provider: Provider) throws
  ```

  <a id="parameters-11"></a>

  #### Parameters

  |                     |                                                                                                                     |
  | ------------------- | ------------------------------------------------------------------------------------------------------------------- |
  | `path`              | The path that is used to identify an `Entry` within the `Archive` file.                                             |
  | `type`              | Indicates the `Entry.EntryType` of the added content.                                                               |
  | `uncompressedSize`  | The uncompressed size of the data that is going to be added with `provider`.                                        |
  | `modificationDate`  | A `Date` describing the file modification date of the `Entry`. Default is the current `Date`.                       |
  | `permissions`       | POSIX file permissions for the `Entry`. Default is `0`o`644` for files and symlinks and `0`o`755` for directories.  |
  | `compressionMethod` | Indicates the `CompressionMethod` that should be applied to `Entry`. By default, no compression will be applied.    |
  | `bufferSize`        | The maximum size of the write buffer and the compression buffer (if needed).                                        |
  | `progress`          | A progress object that can be used to track or cancel the add operation.                                            |
  | `provider`          | A closure that accepts a position and a chunk size. Returns a `Data` chunk.                                         |

- <a id="/s:17IDentitySDK_Swift7ArchiveC6remove_10bufferSize8progressyAA5EntryV_SiSo10NSProgressCSgtKF"></a>

  <a id="//apple_ref/swift/Method/remove(_:bufferSize:progress:)"></a>

  `remove(_:bufferSize:progress:)`

  Remove a ZIP `Entry` from the receiver.

  Throws

  An error if the `Entry` is malformed or the receiver is not writable.

  <a id="declaration-20"></a>

  #### Declaration

  Swift

  ```
  public func remove(_ entry: Entry, bufferSize: Int = defaultReadChunkSize, progress: Progress? = nil) throws
  ```

  <a id="parameters-12"></a>

  #### Parameters

  |              |                                                                              |
  | ------------ | ---------------------------------------------------------------------------- |
  | `entry`      | The `Entry` to remove.                                                       |
  | `bufferSize` | The maximum size for the read and write buffers used during removal.         |
  | `progress`   | A progress object that can be used to track or cancel the remove operation.  |

- <a id="/s:17IDentitySDK_Swift7ArchiveC8addEntry4with10relativeTo17compressionMethod10bufferSize8progressySS_10Foundation3URLVAA011CompressionK0Os6UInt32VSo10NSProgressCSgtKF"></a>

  `addEntry(with:relativeTo:compressionMethod:bufferSize:progress:)`

  <a id="declaration-21"></a>

  #### Declaration

  Swift

  ```
  func addEntry(with path: String, relativeTo baseURL: URL,
                compressionMethod: CompressionMethod = .none,
                bufferSize: UInt32, progress: Progress? = nil) throws
  ```

- <a id="/s:17IDentitySDK_Swift7ArchiveC8addEntry4with7fileURL17compressionMethod10bufferSize8progressySS_10Foundation0I0VAA011CompressionK0Os6UInt32VSo10NSProgressCSgtKF"></a>

  `addEntry(with:fileURL:compressionMethod:bufferSize:progress:)`

  <a id="declaration-22"></a>

  #### Declaration

  Swift

  ```
  func addEntry(with path: String, fileURL: URL, compressionMethod: CompressionMethod = .none,
                bufferSize: UInt32, progress: Progress? = nil) throws
  ```

- <a id="/s:17IDentitySDK_Swift7ArchiveC8addEntry4with4type16uncompressedSize16modificationDate11permissions17compressionMethod06bufferJ08progress8providerySS_AA0F0V0F4TypeOs6UInt32V10Foundation0L0Vs6UInt16VSgAA011CompressionO0OSiSo10NSProgressCSgAT4DataVSi_SitKXEtKF"></a>

  `addEntry(with:type:uncompressedSize:modificationDate:permissions:compressionMethod:bufferSize:progress:provider:)`

  <a id="declaration-23"></a>

  #### Declaration

  Swift

  ```
  func addEntry(with path: String, type: Entry.EntryType, uncompressedSize: UInt32,
                modificationDate: Date = Date(), permissions: UInt16? = nil,
                compressionMethod: CompressionMethod = .none, bufferSize: Int = defaultWriteChunkSize,
                progress: Progress? = nil, provider: (_ position: Int, _ size: Int) throws -> Data) throws
  ```

- <a id="/s:17IDentitySDK_Swift7ArchiveC6remove_10bufferSize8progressyAA5EntryV_s6UInt32VSo10NSProgressCSgtKF"></a>

  `remove(_:bufferSize:progress:)`

  <a id="declaration-24"></a>

  #### Declaration

  Swift

  ```
  func remove(_ entry: Entry, bufferSize: UInt32, progress: Progress? = nil) throws
  ```

<a id="footer"></a>

© 2024 [IDmission](https://www.idmission.com/). All rights reserved. (Last updated: 2024-08-27)

Generated by [jazzy ♪♫ v0.14.2](https://github.com/realm/jazzy), a [Realm](https://realm.io/) project.
