# Swift-tar: A pure Swift TAR archive read/write/extract library

**URL:** <https://forums.swift.org/t/swift-tar-a-pure-swift-tar-archive-read-write-extract-library/85844>\
**Category:** Community Showcase\
**Created:** [April 6, 2026, 11:33pm UTC](https://forums.swift.org/t/swift-tar-a-pure-swift-tar-archive-read-write-extract-library/85844 "2026-04-06T23:33:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kateinoigakukun](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kateinoigakukun/32/16706_2.png) [@kateinoigakukun](https://forums.swift.org/u/kateinoigakukun)\
**Post date:** [April 6, 2026, 11:33pm UTC](https://forums.swift.org/t/swift-tar-a-pure-swift-tar-archive-read-write-extract-library/85844/1 "2026-04-06T23:33:11Z")

</div>

I wrote a TAR reader/writer in Swift.

[swift-tar](https://github.com/kateinoigakukun/swift-tar) is a pure Swift library for reading, writing, and extracting TAR archives.

- Foundation-free - works without Foundation or any system framework
- Cross-platform - macOS, Linux, Windows, WebAssembly, Embedded Swift
- GNU & PAX extensions - transparent handling of long paths, long link names, and PAX extended headers

If you already have the whole archive in memory, the basic API is small:

```swift
import Tar

let archive = Archive(data: archiveBytes)

for entry in archive {
    let path = entry.fields.path()
    let size = entry.fields.size
    print("\(path) (\(size) bytes)")
}

```

For larger inputs, there is also a streaming reader and streaming extractor:

```swift
import Tar

var reader = TarReader()
var extractor = try TarExtractor().streamingExtractor(to: "output")

for chunk in chunks {
    try extractor.consume(reader.append(chunk))
}

try extractor.consume(reader.finish())
let result = try extractor.finish()
print("Extracted \(result.extractedEntries) entries")

```

In one local benchmark, extracting the 3.5 GB `swift-6.3-RELEASE-ubuntu24.04.tar` archive on macOS was slightly faster than `bsdtar` in this setup.

The repo is here: [https://github.com/kateinoigakukun/swift-tar](https://github.com/kateinoigakukun/swift-tar)  
MIT licensed.

Feedback and any use case ideas are welcome.

---

<div class="post-metadata">

**Author:** ![Joannis\_Orlandos](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joannis_orlandos/32/732_2.png) [@Joannis\_Orlandos](https://forums.swift.org/u/Joannis_Orlandos)\
**Post date:** [April 7, 2026, 7:20am UTC](https://forums.swift.org/t/swift-tar-a-pure-swift-tar-archive-read-write-extract-library/85844/2 "2026-04-07T07:20:56Z")

</div>

Thank you! This is excellent for our use cases!
