Skip to content

Commit 8b87ec2

Browse files
authored
Add ArArchiveReaderIterator (#6)
* Add `ArArchiveReaderIterator`.
1 parent 5a82eb9 commit 8b87ec2

File tree

6 files changed

+125
-96
lines changed

6 files changed

+125
-96
lines changed

.github/workflows/buildAndTest.yml

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
1-
name: Build and Test
1+
name: "Build and Test"
22

3-
on: [push, pull_request]
3+
on: ["push", "pull_request"]
44

55
jobs:
6-
TestOnMacOS-10_15-x86_64:
7-
runs-on: macos-10.15
8-
steps:
9-
- uses: actions/checkout@v2
10-
- name: Run tests
11-
run: swift test
12-
TestOnMacOS-11_0-x86_64:
13-
runs-on: macos-11.0
14-
steps:
15-
- uses: actions/checkout@v2
16-
- name: Run tests
17-
run: swift test
18-
# TestOnUbuntu-20_04-ARM:
19-
# runs-on: ubuntu-latest
20-
# steps:
21-
# - uses: actions/checkout@v2
22-
# - uses: uraimo/[email protected]
23-
# with:
24-
# arch: aarch64
25-
# distro: ubuntu20.04
26-
# githubToken: ${{ secrets.GITHUB_TOKEN }}
27-
# run: |
28-
# export DEBIAN_FRONTEND=noninteractive
29-
# apt update -q
30-
# apt install -yq curl sudo
31-
# curl -s https://packagecloud.io/install/repositories/swift-arm/release/script.deb.sh | sudo bash
32-
# apt install -yq swiftlang
33-
# apt update -yq
34-
# swift test
35-
TestOnUbuntu-20_04-x86_64:
36-
runs-on: ubuntu-latest
37-
container: swift:latest
38-
steps:
39-
- uses: actions/checkout@v2
40-
- name: Run tests
41-
run: swift test
42-
TestOnWindows10-x86_64:
43-
runs-on: windows-latest
44-
steps:
45-
- uses: actions/checkout@v2
46-
- uses: seanmiddleditch/gha-setup-vsdevenv@master
47-
- name: Install swift-5.4-RELEASE
48-
run: Install-Binary -Url "https://swift.org/builds/swift-5.4-release/windows10/swift-5.4-RELEASE/swift-5.4-RELEASE-windows10.exe" -Name "installer.exe" -ArgumentList ("-q")
49-
- name: Set Environment Variables
50-
run: |
51-
echo "SDKROOT=C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
52-
echo "DEVELOPER_DIR=C:\Library\Developer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
53-
- name: Adjust Paths
54-
run: echo "C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin;C:\Library\Swift-development\bin;C:\Library\icu-67\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
55-
- name: Install Supporting Files
56-
shell: cmd
57-
run: |
58-
copy "%SDKROOT%\usr\share\ucrt.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap"
59-
copy "%SDKROOT%\usr\share\visualc.modulemap" "%VCToolsInstallDir%\include\module.modulemap"
60-
copy "%SDKROOT%\usr\share\visualc.apinotes" "%VCToolsInstallDir%\include\visualc.apinotes"
61-
copy "%SDKROOT%\usr\share\winsdk.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"
62-
- name: Test
63-
run: "swift build"
64-
TestBuildingOnMacOS-11_0-ARM64:
65-
runs-on: macos-11.0
66-
steps:
67-
- uses: actions/checkout@v2
68-
- name: Run tests
69-
run: swift build --arch arm64
6+
TestOnMacOS-10_15-x86_64:
7+
runs-on: "macos-10.15"
8+
steps:
9+
- uses: "actions/checkout@v2"
10+
- name: "Run tests"
11+
run: "swift test"
12+
TestOnMacOS-11_0-x86_64:
13+
runs-on: "macos-11.0"
14+
steps:
15+
- uses: "actions/checkout@v2"
16+
- name: "Run tests"
17+
run: "swift test"
18+
# TestOnUbuntu-20_04-ARM:
19+
# runs-on: ubuntu-latest
20+
# steps:
21+
# - uses: actions/checkout@v2
22+
# - uses: uraimo/[email protected]
23+
# with:
24+
# arch: aarch64
25+
# distro: ubuntu20.04
26+
# githubToken: ${{ secrets.GITHUB_TOKEN }}
27+
# run: |
28+
# export DEBIAN_FRONTEND=noninteractive
29+
# apt update -q
30+
# apt install -yq curl sudo
31+
# curl -s https://packagecloud.io/install/repositories/swift-arm/release/script.deb.sh | sudo bash
32+
# apt install -yq swiftlang
33+
# apt update -yq
34+
# swift test
35+
TestOnUbuntu-20_04-x86_64:
36+
runs-on: "ubuntu-latest"
37+
container: "swift:latest"
38+
steps:
39+
- uses: "actions/checkout@v2"
40+
- name: "Run tests"
41+
run: "swift test"
42+
TestOnWindows10-x86_64:
43+
runs-on: "windows-latest"
44+
steps:
45+
- uses: "actions/checkout@v2"
46+
- uses: "seanmiddleditch/gha-setup-vsdevenv@master"
47+
- name: "Install swift-5.4-RELEASE"
48+
run: 'Install-Binary -Url "https://swift.org/builds/swift-5.4-release/windows10/swift-5.4-RELEASE/swift-5.4-RELEASE-windows10.exe" -Name "installer.exe" -ArgumentList ("-q")'
49+
- name: "Set Environment Variables"
50+
run: |
51+
echo "SDKROOT=C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
52+
echo "DEVELOPER_DIR=C:\Library\Developer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
53+
- name: "Adjust Paths"
54+
run: 'echo "C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin;C:\Library\Swift-development\bin;C:\Library\icu-67\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append'
55+
- name: "Install Supporting Files"
56+
shell: "cmd"
57+
run: |
58+
copy "%SDKROOT%\usr\share\ucrt.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap"
59+
copy "%SDKROOT%\usr\share\visualc.modulemap" "%VCToolsInstallDir%\include\module.modulemap"
60+
copy "%SDKROOT%\usr\share\visualc.apinotes" "%VCToolsInstallDir%\include\visualc.apinotes"
61+
copy "%SDKROOT%\usr\share\winsdk.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"
62+
- name: "Test"
63+
run: "swift build"
64+
TestBuildingOnMacOS-11_0-ARM64:
65+
runs-on: "macos-11.0"
66+
steps:
67+
- uses: "actions/checkout@v2"
68+
- name: "Run tests"
69+
run: "swift build --arch arm64"
Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
name: Generate Documentation
1+
name: "Generate Documentation"
22

3-
on: push
3+
on:
4+
push:
5+
branches:
6+
- "main"
47

58
jobs:
6-
GenerateDocumentation:
7-
runs-on: ubuntu-latest
8-
steps:
9-
- uses: actions/checkout@v2
10-
- name: Generate Documentation
11-
uses: SwiftDocOrg/swift-doc@master
12-
with:
13-
inputs: "Sources"
14-
module-name: ArArchiveKit
15-
format: html
16-
base-url: "https://lebje.github.io/ArArchiveKit/"
17-
output: ./.build/documentation
18-
- name: Change Permissions
19-
run: sudo chmod o+r -R ./.build/documentation
20-
- name: Deploy to GitHub Pages
21-
uses: peaceiris/actions-gh-pages@v3
22-
with:
23-
github_token: ${{ secrets.GITHUB_TOKEN }}
24-
publish_dir: ./.build/documentation
9+
"GenerateDocumentation":
10+
runs-on: "ubuntu-latest"
11+
steps:
12+
- uses: "actions/checkout@v2"
13+
- name: "Generate Documentation"
14+
uses: "SwiftDocOrg/swift-doc@master"
15+
with:
16+
inputs: "Sources"
17+
module-name: "ArArchiveKit"
18+
format: "html"
19+
base-url: "https://lebje.github.io/ArArchiveKit/"
20+
output: "./.build/documentation"
21+
- name: "Change Permissions"
22+
run: "sudo chmod o+r -R ./.build/documentation"
23+
- name: "Deploy to GitHub Pages"
24+
uses: "peaceiris/actions-gh-pages@v3"
25+
with:
26+
github_token: ${{ secrets.GITHUB_TOKEN }}
27+
publish_dir: "./.build/documentation"

.pre-commit-config.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/hodovani/pre-commit-swift
5-
rev: 0551a937b9f98a839fd98d2c3e6ce0b6c0a1e093
6-
hooks:
7-
- id: swift-format
4+
- repo: "https://github.com/hodovani/pre-commit-swift"
5+
rev: "0551a937b9f98a839fd98d2c3e6ce0b6c0a1e093"
6+
hooks:
7+
- id: "swift-format"
8+
name: "Format Swift"
9+
- repo: "https://github.com/pre-commit/mirrors-prettier"
10+
rev: "4309ae0bc8b9f39c207bca9c5040ec8a35561a41"
11+
hooks:
12+
- id: "prettier"
13+
name: "Format Markdown"
14+
tags: ["md"]

.prettierrc.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
trailingComma = "es5"
2+
tabWidth = 4
3+
singleQuote = false
4+
useTabs = true

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.3](https://github.com/LebJe/ArArchiveKit/releases/tag/0.2.3) - 2021-06-22
9+
10+
### Added
11+
12+
- Added `ArArchiveReaderIterator`.
13+
814
## [0.2.2](https://github.com/LebJe/ArArchiveKit/releases/tag/0.2.2) - 2021-06-11
915

1016
### Fixed

Sources/ArArchiveKit/ArArchiveReader.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,25 @@ public struct ArArchiveReader {
146146
}
147147
}
148148

149-
extension ArArchiveReader: IteratorProtocol, Sequence {
149+
extension ArArchiveReader: Sequence {
150+
public func makeIterator() -> ArArchiveReaderIterator {
151+
ArArchiveReaderIterator(archive: self)
152+
}
153+
}
154+
155+
public struct ArArchiveReaderIterator: IteratorProtocol {
150156
public typealias Element = (Header, [UInt8])
151157

152-
public mutating func next() -> Element? {
153-
if self.currentIndex > self.headers.count - 1 {
158+
let archive: ArArchiveReader
159+
var currentIndex = 0
160+
161+
public mutating func next() -> (Header, [UInt8])? {
162+
if self.currentIndex > self.archive.headers.count - 1 {
154163
return nil
155164
}
156165

157-
let bytes = self[currentIndex]
158-
let h = self.headers[self.currentIndex]
166+
let bytes = self.archive[self.currentIndex]
167+
let h = self.archive.headers[self.currentIndex]
159168
self.currentIndex += 1
160169

161170
return (h, bytes)

0 commit comments

Comments
 (0)