Skip to content

Commit

Permalink
Add ArArchiveReaderIterator (#6)
Browse files Browse the repository at this point in the history
* Add `ArArchiveReaderIterator`.
  • Loading branch information
LebJe authored Jun 22, 2021
1 parent 5a82eb9 commit 8b87ec2
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 96 deletions.
132 changes: 66 additions & 66 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
name: Build and Test
name: "Build and Test"

on: [push, pull_request]
on: ["push", "pull_request"]

jobs:
TestOnMacOS-10_15-x86_64:
runs-on: macos-10.15
steps:
- uses: actions/checkout@v2
- name: Run tests
run: swift test
TestOnMacOS-11_0-x86_64:
runs-on: macos-11.0
steps:
- uses: actions/checkout@v2
- name: Run tests
run: swift test
# TestOnUbuntu-20_04-ARM:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: uraimo/[email protected]
# with:
# arch: aarch64
# distro: ubuntu20.04
# githubToken: ${{ secrets.GITHUB_TOKEN }}
# run: |
# export DEBIAN_FRONTEND=noninteractive
# apt update -q
# apt install -yq curl sudo
# curl -s https://packagecloud.io/install/repositories/swift-arm/release/script.deb.sh | sudo bash
# apt install -yq swiftlang
# apt update -yq
# swift test
TestOnUbuntu-20_04-x86_64:
runs-on: ubuntu-latest
container: swift:latest
steps:
- uses: actions/checkout@v2
- name: Run tests
run: swift test
TestOnWindows10-x86_64:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: seanmiddleditch/gha-setup-vsdevenv@master
- name: Install swift-5.4-RELEASE
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")
- name: Set Environment Variables
run: |
echo "SDKROOT=C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "DEVELOPER_DIR=C:\Library\Developer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Adjust Paths
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
- name: Install Supporting Files
shell: cmd
run: |
copy "%SDKROOT%\usr\share\ucrt.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap"
copy "%SDKROOT%\usr\share\visualc.modulemap" "%VCToolsInstallDir%\include\module.modulemap"
copy "%SDKROOT%\usr\share\visualc.apinotes" "%VCToolsInstallDir%\include\visualc.apinotes"
copy "%SDKROOT%\usr\share\winsdk.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"
- name: Test
run: "swift build"
TestBuildingOnMacOS-11_0-ARM64:
runs-on: macos-11.0
steps:
- uses: actions/checkout@v2
- name: Run tests
run: swift build --arch arm64
TestOnMacOS-10_15-x86_64:
runs-on: "macos-10.15"
steps:
- uses: "actions/checkout@v2"
- name: "Run tests"
run: "swift test"
TestOnMacOS-11_0-x86_64:
runs-on: "macos-11.0"
steps:
- uses: "actions/checkout@v2"
- name: "Run tests"
run: "swift test"
# TestOnUbuntu-20_04-ARM:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: uraimo/[email protected]
# with:
# arch: aarch64
# distro: ubuntu20.04
# githubToken: ${{ secrets.GITHUB_TOKEN }}
# run: |
# export DEBIAN_FRONTEND=noninteractive
# apt update -q
# apt install -yq curl sudo
# curl -s https://packagecloud.io/install/repositories/swift-arm/release/script.deb.sh | sudo bash
# apt install -yq swiftlang
# apt update -yq
# swift test
TestOnUbuntu-20_04-x86_64:
runs-on: "ubuntu-latest"
container: "swift:latest"
steps:
- uses: "actions/checkout@v2"
- name: "Run tests"
run: "swift test"
TestOnWindows10-x86_64:
runs-on: "windows-latest"
steps:
- uses: "actions/checkout@v2"
- uses: "seanmiddleditch/gha-setup-vsdevenv@master"
- name: "Install swift-5.4-RELEASE"
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")'
- name: "Set Environment Variables"
run: |
echo "SDKROOT=C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "DEVELOPER_DIR=C:\Library\Developer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: "Adjust Paths"
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'
- name: "Install Supporting Files"
shell: "cmd"
run: |
copy "%SDKROOT%\usr\share\ucrt.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap"
copy "%SDKROOT%\usr\share\visualc.modulemap" "%VCToolsInstallDir%\include\module.modulemap"
copy "%SDKROOT%\usr\share\visualc.apinotes" "%VCToolsInstallDir%\include\visualc.apinotes"
copy "%SDKROOT%\usr\share\winsdk.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"
- name: "Test"
run: "swift build"
TestBuildingOnMacOS-11_0-ARM64:
runs-on: "macos-11.0"
steps:
- uses: "actions/checkout@v2"
- name: "Run tests"
run: "swift build --arch arm64"
45 changes: 24 additions & 21 deletions .github/workflows/generateDocumentation.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
name: Generate Documentation
name: "Generate Documentation"

on: push
on:
push:
branches:
- "main"

jobs:
GenerateDocumentation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Generate Documentation
uses: SwiftDocOrg/swift-doc@master
with:
inputs: "Sources"
module-name: ArArchiveKit
format: html
base-url: "https://lebje.github.io/ArArchiveKit/"
output: ./.build/documentation
- name: Change Permissions
run: sudo chmod o+r -R ./.build/documentation
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./.build/documentation
"GenerateDocumentation":
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- name: "Generate Documentation"
uses: "SwiftDocOrg/swift-doc@master"
with:
inputs: "Sources"
module-name: "ArArchiveKit"
format: "html"
base-url: "https://lebje.github.io/ArArchiveKit/"
output: "./.build/documentation"
- name: "Change Permissions"
run: "sudo chmod o+r -R ./.build/documentation"
- name: "Deploy to GitHub Pages"
uses: "peaceiris/actions-gh-pages@v3"
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: "./.build/documentation"
15 changes: 11 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/hodovani/pre-commit-swift
rev: 0551a937b9f98a839fd98d2c3e6ce0b6c0a1e093
hooks:
- id: swift-format
- repo: "https://github.com/hodovani/pre-commit-swift"
rev: "0551a937b9f98a839fd98d2c3e6ce0b6c0a1e093"
hooks:
- id: "swift-format"
name: "Format Swift"
- repo: "https://github.com/pre-commit/mirrors-prettier"
rev: "4309ae0bc8b9f39c207bca9c5040ec8a35561a41"
hooks:
- id: "prettier"
name: "Format Markdown"
tags: ["md"]
4 changes: 4 additions & 0 deletions .prettierrc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trailingComma = "es5"
tabWidth = 4
singleQuote = false
useTabs = true
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.3](https://github.com/LebJe/ArArchiveKit/releases/tag/0.2.3) - 2021-06-22

### Added

- Added `ArArchiveReaderIterator`.

## [0.2.2](https://github.com/LebJe/ArArchiveKit/releases/tag/0.2.2) - 2021-06-11

### Fixed
Expand Down
19 changes: 14 additions & 5 deletions Sources/ArArchiveKit/ArArchiveReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,25 @@ public struct ArArchiveReader {
}
}

extension ArArchiveReader: IteratorProtocol, Sequence {
extension ArArchiveReader: Sequence {
public func makeIterator() -> ArArchiveReaderIterator {
ArArchiveReaderIterator(archive: self)
}
}

public struct ArArchiveReaderIterator: IteratorProtocol {
public typealias Element = (Header, [UInt8])

public mutating func next() -> Element? {
if self.currentIndex > self.headers.count - 1 {
let archive: ArArchiveReader
var currentIndex = 0

public mutating func next() -> (Header, [UInt8])? {
if self.currentIndex > self.archive.headers.count - 1 {
return nil
}

let bytes = self[currentIndex]
let h = self.headers[self.currentIndex]
let bytes = self.archive[self.currentIndex]
let h = self.archive.headers[self.currentIndex]
self.currentIndex += 1

return (h, bytes)
Expand Down

0 comments on commit 8b87ec2

Please sign in to comment.