{"id":15130635,"url":"https://github.com/lebje/ararchivekit","last_synced_at":"2025-10-23T07:30:30.307Z","repository":{"id":48676651,"uuid":"348723469","full_name":"LebJe/ArArchiveKit","owner":"LebJe","description":"A simple, 0-dependency Swift package for reading and writing ar archives. Inspired by ar: https://github.com/blakesmith/ar","archived":false,"fork":false,"pushed_at":"2021-11-01T17:46:01.000Z","size":152,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-10T01:34:19.127Z","etag":null,"topics":["ar-archives","archive","archiver","ios","linux","macos","swift","swift-package","swift5","swift5-3","tvos","windows-10"],"latest_commit_sha":null,"homepage":"https://lebje.github.io/ArArchiveKit","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LebJe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-17T13:38:59.000Z","updated_at":"2024-11-02T09:26:24.000Z","dependencies_parsed_at":"2022-08-24T08:10:08.896Z","dependency_job_id":null,"html_url":"https://github.com/LebJe/ArArchiveKit","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LebJe%2FArArchiveKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LebJe%2FArArchiveKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LebJe%2FArArchiveKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LebJe%2FArArchiveKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LebJe","download_url":"https://codeload.github.com/LebJe/ArArchiveKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237793861,"owners_count":19367421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ar-archives","archive","archiver","ios","linux","macos","swift","swift-package","swift5","swift5-3","tvos","windows-10"],"created_at":"2024-09-26T03:03:06.543Z","updated_at":"2025-10-23T07:30:29.983Z","avatar_url":"https://github.com/LebJe.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ArArchiveKit\n\n**A simple, 0-dependency Swift package for reading and writing [`ar`](\u003chttps://en.wikipedia.org/wiki/Ar_(Unix)\u003e) archives. Inspired by [ar](https://github.com/blakesmith/ar).**\n\n[![Swift 5.3](https://img.shields.io/badge/Swift-5.3-brightgreen?logo=swift)](https://swift.org)\n[![SPM Compatible](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://swift.org/package-manager)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FLebJe%2FArArchiveKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/LebJe/ArArchiveKit)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FLebJe%2FArArchiveKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/LebJe/ArArchiveKit)\n[![](https://img.shields.io/github/v/tag/LebJe/ArArchiveKit)](https://github.com/LebJe/ArArchiveKit/releases)\n[![Build and Test](https://github.com/LebJe/ArArchiveKit/workflows/Build%20and%20Test/badge.svg)](https://github.com/LebJe/ArArchiveKit/actions?query=workflow%3A%22Build+and+Test%22)\n\n# Table of Contents\n\n\u003c!--ts--\u003e\n\n-   [ArArchiveKit](#ararchivekit)\n-   [Table of Contents](#table-of-contents)\n    -   [ar Variations](#ar-variations)\n    -   [Installation](#installation)\n        -   [Swift Package Manager](#swift-package-manager)\n    -   [Usage](#usage)\n        -   [Writing Archives](#writing-archives)\n        -   [Reading Archives](#reading-archives)\n            -   [Iteration](#iteration)\n            -   [Subscript](#subscript)\n    -   [Examples](#examples)\n    -   [Other Platforms](#other-platforms)\n        -   [Windows](#windows)\n    -   [Contributing](#contributing)\n\n\u003c!-- Added by: lebje, at: Wed Jul 14 12:30:02 EDT 2021 --\u003e\n\n\u003c!--te--\u003e\n\nCreated by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)\n\nDocumentation is available [here](https://lebje.github.io/ArArchiveKit).\n\n## `ar` Variations\n\nArArchiveKit supports the \"Common\", BSD, and SVR4/GNU variations of `ar` as described in [FreeBSD manpages](https://www.freebsd.org/cgi/man.cgi?query=ar\u0026sektion=5).\n\nSupport for symbol tables may come soon.\n\n## Installation\n\n### Swift Package Manager\n\nAdd this to the `dependencies` array in `Package.swift`:\n\n```swift\n.package(url: \"https://github.com/LebJe/ArArchiveKit.git\", from: \"0.3.0\")\n```\n\nAlso add this to the `targets` array in the aforementioned file:\n\n```swift\n.product(name: \"ArArchiveKit\", package: \"ArArchiveKit\")\n```\n\n## Usage\n\n### Writing Archives\n\nTo write archives, you'll need a `ArArchiveWriter`:\n\n```swift\nvar writer = ArArchiveWriter()\n```\n\nOnce you have your writer, you must create a `Header`, that describes the file you wish to add to your archive:\n\n```swift\nvar time: Int = 1615929568\n\n// You can also use date\nlet date: Date = ...\ntime = Int(date.timeIntervalSince1970)\n\nlet header = Header(\n\t// `name` will be truncated to 16 characters.\n\tname: \"hello.txt\",\n\tmodificationTime: time\n)\n```\n\nOnce you have your `Header`, you can write it, along with the contents of your file, to the archive:\n\n```swift\n// Without Foundation\nvar contents = [\n\tUInt8(ascii: \"H\"),\n\tUInt8(ascii: \"e\"),\n\tUInt8(ascii: \"l\"),\n\tUInt8(ascii: \"l\"),\n\tUInt8(ascii: \"o\"),\n]\n\n// With Foundation\n\nlet myData: Data = \"Hello\".data(using .utf8)!\n\ncontents = Array\u003cUInt8\u003e(myData)\n\nwriter.addFile(header: header, contents: contents)\n```\n\nIf you have a text file, use the overloaded version of `addFile`:\n\n```swift\nwriter.addFile(header: header, contents: \"Hello\")\n```\n\nOnce you have added your files, you can get the archive like this:\n\n```swift\n// Call finalize to get the binary representation (Array\u003cUInt8\u003e) of the archive.\nlet bytes = writer.finalize()\n\n// You convert it to data like this:\nlet data = Data(bytes)\n\n// And write it:\ntry data.write(to: URL(fileURLWithPath: \"myArchive.a\"))\n```\n\n### Reading Archives\n\nTo read archives, you need an `ArArchiveReader`:\n\n```swift\n// myData is the bytes of the archive.\nlet myData: Data = ...\n\nlet reader = ArArchiveReader(archive: Array\u003cUInt8\u003e(myData))\n```\n\nOnce you have your reader, there are several ways you can retrieve the data:\n\n#### Iteration\n\nYou can iterate though all the files in the archive like this:\n\n```swift\nfor (header, data) in reader {\n   // `data` is `Array\u003cUInt8\u003e` that contains the raw bytes of the file in the archive.\n   // `header` is the `Header` that describes the `data`.\n\n   // if you know `data` is a `String`, then you can use this initializer:\n   let str = String(data)\n}\n```\n\n#### Subscript\n\nAccessing data through the `subscript` is useful when you only need to access a few items in a large archive:\n\n```swift\n\n// The subscript provides you with random access to any file in the archive:\nlet firstFile = reader[0]\nlet fifthFile = reader[6]\n```\n\nYou can also use the version of the subscript that takes a `Header` - useful for when you have a `Header`, but not the index of that header.\n\n```swift\nlet header = reader.headers.first(where: { $0.name.contains(\".swift\") })!\nlet data = reader[header: header]\n```\n\n## Examples\n\n-   `Exaples/ReaderAndWriter`: This example shows how to use ArArchiveKit to read or extract entries from any archive using only `Darwin.C` (macOS), `Glibc` (Linux) or `ucrt` (Windows (not tested)).\n\n## Other Platforms\n\nArArchiveKit doesn't depend on any library, `Foundation`, or `Darwin`/`Glibc`/`ucrt` - only the Swift standard library. It should compile on any platform where the standard library compiles.\n\n### Windows\n\nArArchiveKit is currently being built on Windows, but not tested, as the [Swift Package Manager Resources](https://github.com/apple/swift-evolution/blob/main/proposals/0271-package-manager-resources.md) doesn't seem to work (or isn't available) on Windows.\n\n## Contributing\n\nBefore committing, please install [pre-commit](https://pre-commit.com), and [swift-format](https://github.com/nicklockwood/SwiftFormat) and install the pre-commit hook:\n\n```bash\n$ brew bundle # install the packages specified in Brewfile\n$ pre-commit install\n\n# Commit your changes.\n```\n\nTo install pre-commit on other platforms, refer to the [documentation](https://pre-commit.com/#install).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flebje%2Fararchivekit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flebje%2Fararchivekit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flebje%2Fararchivekit/lists"}