Skip to content

Commit 5116cc4

Browse files
committed
tar: Extract the tar writer into its own module
Preparation for refactoring and unit testing
1 parent ec08871 commit 5116cc4

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let package = Package(
4040
.executableTarget(
4141
name: "containertool",
4242
dependencies: [
43-
.target(name: "ContainerRegistry"), .target(name: "VendorCNIOExtrasZlib"),
43+
.target(name: "ContainerRegistry"), .target(name: "VendorCNIOExtrasZlib"), .target(name: "Tar"),
4444
.product(name: "ArgumentParser", package: "swift-argument-parser"),
4545
],
4646
swiftSettings: [.swiftLanguageMode(.v5)]
@@ -51,7 +51,7 @@ let package = Package(
5151
dependencies: [],
5252
path: "Vendor/github.com/apple/swift-nio-extras/Sources/CNIOExtrasZlib",
5353
linkerSettings: [.linkedLibrary("z")]
54-
),
54+
), .target(name: "Tar"),
5555
.target(
5656
// Vendored from https://github.com/apple/swift-package-manager with modifications
5757
name: "Basics",

Sources/containertool/tar.swift renamed to Sources/Tar/tar.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ let CONTTYPE = "7" // reserved
143143
let XHDTYPE = "x" // Extended header referring to the next file in the archive
144144
let XGLTYPE = "g" // Global extended header
145145

146-
func tar(_ bytes: [UInt8], filename: String = "app") -> [UInt8] {
146+
/// Creates a tar archive containing a single file
147+
/// - Parameters:
148+
/// - bytes: The file's body data
149+
/// - filename: The file's name in the archive
150+
/// - Returns: A tar archive containing the file
151+
public func tar(_ bytes: [UInt8], filename: String = "app") -> [UInt8] {
147152
// A file entry consists of a file header followed by the
148153
// contents of the file. The header includes information such as
149154
// the file name, size and permissions. Different versions of
@@ -187,4 +192,9 @@ func tar(_ bytes: [UInt8], filename: String = "app") -> [UInt8] {
187192
return hdr
188193
}
189194

190-
func tar(_ data: Data, filename: String) -> [UInt8] { tar([UInt8](data), filename: filename) }
195+
/// Creates a tar archive containing a single file
196+
/// - Parameters:
197+
/// - data: The file's body data
198+
/// - filename: The file's name in the archive
199+
/// - Returns: A tar archive containing the file
200+
public func tar(_ data: Data, filename: String) -> [UInt8] { tar([UInt8](data), filename: filename) }

Sources/containertool/containertool.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import ArgumentParser
1616
import Foundation
1717
import ContainerRegistry
18+
import Tar
1819
import Basics
1920

2021
extension Swift.String: Swift.Error {}

0 commit comments

Comments
 (0)