<!--
{
  "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/ArchiveByteStream/withFileStream(fd:automaticClose:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Apple Archive",
      "AppleArchive"
    ],
    "preciseIdentifier" : "s:12AppleArchive0B10ByteStreamC08withFileD02fd14automaticClose_x6System0F10DescriptorV_SbxACKXEtKlFZ"
  },
  "title" : "withFileStream(fd:automaticClose:_:)"
}
-->

# withFileStream(fd:automaticClose:_:)

Calls the given closure with a file stream created from the specified file descriptor.

```
static func withFileStream<E>(fd: FileDescriptor, automaticClose: Bool = true, _ body: (ArchiveByteStream) throws -> E) throws -> E
```

## Parameters

`fd`

The file descriptor that you have previously opened with `open(2)`.

`automaticClose`

A Boolean value that specifies whether to close the file descriptor when you close the stream.

`body`

A closure with the archive byte stream passed as a parameter.

## Return Value

The result of the closure.

---

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)