<!--
{
  "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/withExtractStream(extractingTo:selectUsing:flags:threadCount:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Apple Archive",
      "AppleArchive"
    ],
    "preciseIdentifier" : "s:12AppleArchive0B6StreamC011withExtractC012extractingTo11selectUsing5flags11threadCount_x6System8FilePathV_AA0B6HeaderC18EntryMessageStatusVAM0qR0V_AkM0Q10FilterDataOSgtcSgAA0B5FlagsVSixACKXEtKlFZ"
  },
  "title" : "withExtractStream(extractingTo:selectUsing:flags:threadCount:_:)"
}
-->

# withExtractStream(extractingTo:selectUsing:flags:threadCount:_:)

Calls the given closure with an extract output archive stream.

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

## 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.

`body`

A closure with the archive stream passed as a parameter.

## Return Value

The result of the closure.

## Discussion

This function opens a stream created by [`extractStream(extractingTo:selectUsing:flags:threadCount:)`](/documentation/AppleArchive/ArchiveStream/extractStream(extractingTo:selectUsing:flags:threadCount:)), calls the specified closure, and closes the stream.

---

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)