<!--
{
  "documentType" : "article",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/decompressing-single-files",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Decompressing single files"
}
-->

# Decompressing single files

Recreate a single file from a compressed file.

## Discussion

In this article, you’ll learn how to use AppleArchive to decompress a previously compressed file, and write the decompressed data to a file.

The code below decompresses the file generated using the steps explained in <doc://com.apple.documentation/documentation/Accelerate/compressing-single-files>.

### Create the file stream to read the source archive

The <doc://com.apple.documentation/documentation/AppleArchive/ArchiveByteStream> class provides static factory methods that create streams for different functions. In this case, use <doc://com.apple.documentation/documentation/AppleArchive/ArchiveByteStream/fileStream(path:mode:options:permissions:)> to create a byte stream that reads the source file:

```swift
let archiveFilePath = FilePath(NSTemporaryDirectory() + "myFile.pdf.lzfse")

guard let readFileStream = ArchiveByteStream.fileStream(
        path: archiveFilePath,
        mode: .readOnly,
        options: [ ],
        permissions: FilePermissions(rawValue: 0o644)) else {
    return
}
defer {
    try? readFileStream.close()
}
```

### Create the file stream to write the decompressed file

You also use <doc://com.apple.documentation/documentation/AppleArchive/ArchiveByteStream/fileStream(path:mode:options:permissions:)> to create the file stream that writes the decompressed file to the file system. In this case, use the <doc://com.apple.documentation/documentation/System/FileDescriptor/AccessMode/writeOnly> mode:

```swift
let destinationFilePath = FilePath(NSTemporaryDirectory() + "myFile_decompressed.pdf")

guard let writeFileStream = ArchiveByteStream.fileStream(
        path: destinationFilePath,
        mode: .writeOnly,
        options: [ .create ],
        permissions: FilePermissions(rawValue: 0o644)) else {
    return
}
defer {
    try? writeFileStream.close()
}
```

### Create the decompression stream

Create the decompression stream. Specify the file-reading stream as the input stream that provides the compressed data:

```swift
guard let decompressStream = ArchiveByteStream.decompressionStream(readingFrom: readFileStream) else {
    print("unable to create compress stream")
    return
}
defer {
    try? decompressStream.close()
}
```

### Decompress the source archive

Finally, call <doc://com.apple.documentation/documentation/AppleArchive/ArchiveByteStream/process(readingFrom:writingTo:)> to write the output of the decompression stream to the file-writing stream:

```swift
do {
    _ = try ArchiveByteStream.process(readingFrom: decompressStream,
                                      writingTo: writeFileStream)
} catch {
    print("Handle `ArchiveByteStream.process` failed.")
}
```

On return, `myFile_decompressed.pdf` exists in <doc://com.apple.documentation/documentation/Foundation/NSTemporaryDirectory()> and contains the decompressed contents of `myFile.pdf.lzfse`.

---

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)