Skip to content

Commit 9016863

Browse files
authored
tar: Remove dependency on Foundation (#76)
Motivation ---------- Libraries should have as few dependencies as possible. `Tar` only depends on Foundation because of a convenience wrapper function which can easily be handled in the caller. Modifications ------------- * Remove the `public func tar(_ data: Data, filename: String) throws -> [UInt8]` wrapper Result ------ No functional change to `containertool`. `Tar` no longer depends on Foundation. Test Plan --------- Existing tests continue to pass.
1 parent 5051545 commit 9016863

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

Sources/Tar/tar.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import struct Foundation.Data
16-
1715
// This file defines a basic tar writer which produces POSIX tar files.
1816
// This avoids the need to depend on a system-provided tar binary.
1917
//
@@ -92,7 +90,7 @@ func octal6(_ value: Int) -> String {
9290
// which causes it to return an empty string from time to time when running the tests
9391
// in parallel using swift-testing: https://github.com/swiftlang/swift-corelibs-foundation/issues/5152
9492
let str = String(value, radix: 8)
95-
return String(repeating: "0", count: 6 - str.count).appending(str)
93+
return String(repeating: "0", count: 6 - str.count) + str
9694
}
9795

9896
/// Serializes an integer to an 11 character octal representation.
@@ -105,7 +103,7 @@ func octal11(_ value: Int) -> String {
105103
// which causes it to return an empty string from time to time when running the tests
106104
// in parallel using swift-testing: https://github.com/swiftlang/swift-corelibs-foundation/issues/5152
107105
let str = String(value, radix: 8)
108-
return String(repeating: "0", count: 11 - str.count).appending(str)
106+
return String(repeating: "0", count: 11 - str.count) + str
109107
}
110108

111109
// These ranges define the offsets of the standard fields in a Tar header.
@@ -343,16 +341,6 @@ public func tar(_ bytes: [UInt8], filename: String = "app") throws -> [UInt8] {
343341
return archive
344342
}
345343

346-
/// Creates a tar archive containing a single file
347-
/// - Parameters:
348-
/// - data: The file's body data
349-
/// - filename: The file's name in the archive
350-
/// - Returns: A tar archive containing the file
351-
/// - Throws: If the filename is invalid
352-
public func tar(_ data: Data, filename: String) throws -> [UInt8] {
353-
try tar([UInt8](data), filename: filename)
354-
}
355-
356344
/// Represents a tar archive
357345
public struct Archive {
358346
/// The files, directories and other members of the archive

Sources/containertool/containertool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ enum AllowHTTP: String, ExpressibleByArgument, CaseIterable { case source, desti
149149
// MARK: Build the application layer
150150

151151
let payload_name = executableURL.lastPathComponent
152-
let tardiff = try tar(payload, filename: payload_name)
152+
let tardiff = try tar([UInt8](payload), filename: payload_name)
153153
log("Built application layer")
154154

155155
// MARK: Upload the application layer

0 commit comments

Comments
 (0)