<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppleArchive",
  "identifier" : "/documentation/AppleArchive/ArchiveStream/extractStream(extractingTo:selectUsing:flags:threadCount:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Apple Archive",
      "AppleArchive"
    ],
    "preciseIdentifier" : "s:12AppleArchive0B6StreamC07extractC012extractingTo11selectUsing5flags11threadCountACSg6System8FilePathV_AA0B6HeaderC18EntryMessageStatusVAN0pQ0V_AlN0P10FilterDataOSgtcSgAA0B5FlagsVSitFZ"
  },
  "title" : "extractStream(extractingTo:selectUsing:flags:threadCount:)"
}
-->

# extractStream(extractingTo:selectUsing:flags:threadCount:)

Opens an extract output archive stream.

```
static func extractStream(extractingTo directory: FilePath, selectUsing filter: ArchiveHeader.EntryFilter? = nil, flags: ArchiveFlags = [], threadCount: Int = 0) -> ArchiveStream?
```

## Parameters

`directory`

The directory that the archive stream writes the extracted entries to.

`filter`

A closure that’s called for each entry that’s received by the stream.

`flags`

Flags that control the behavior of the operation.

`threadCount`

The number of worker threads that the operation uses, set to `0` for default.

## Return Value

A new archive stream.

## Discussion

For each entry received by the stream, the operation first calls the `filter` closure with the [`extractBegin`](/documentation/AppleArchive/ArchiveHeader/EntryMessage/extractBegin) message and `data` referencing an [`ArchiveHeader`](/documentation/AppleArchive/ArchiveHeader) instance.

If the `filter` closure returns [`skip`](/documentation/AppleArchive/ArchiveHeader/EntryMessageStatus/skip), the stream discards the entry. Otherwise, the stream extracts the entry, and then executes the closure with the [`extractAttributes`](/documentation/AppleArchive/ArchiveHeader/EntryMessage/extractAttributes), [`extractXAT`](/documentation/AppleArchive/ArchiveHeader/EntryMessage/extractXAT), [`extractACL`](/documentation/AppleArchive/ArchiveHeader/EntryMessage/extractACL) messages. Following this closure make modifications to the extracted fields before writing to the filesystem.

When the stream fully extracts the entry, it then executes the closure with an [`extractEnd`](/documentation/AppleArchive/ArchiveHeader/EntryMessage/extractEnd) message. When the entry extraction fails, the stream executes the closure with [`extractFail`](/documentation/AppleArchive/ArchiveHeader/EntryMessage/extractFail). If the closure returns [`cancel`](/documentation/AppleArchive/ArchiveHeader/EntryMessageStatus/cancel), the stream aborts processing. Otherwise, processing continues.

The stream calls [`extractBegin`](/documentation/AppleArchive/ArchiveHeader/EntryMessage/extractBegin) messages in archive order and are always the first call for a given entry.

The [`extractEnd`](/documentation/AppleArchive/ArchiveHeader/EntryMessage/extractEnd) or [`extractFail`](/documentation/AppleArchive/ArchiveHeader/EntryMessage/extractFail) messages are always the last call for a given entry, and aren’t necessarily called in the same order. In particular, for directories, the stream may call [`extractEnd`](/documentation/AppleArchive/ArchiveHeader/EntryMessage/extractEnd) only after extraction of all directory contents is complete.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)