Skip to content

tar: Remove dependency on Foundation #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions Sources/Tar/tar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
//
//===----------------------------------------------------------------------===//

import struct Foundation.Data

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

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

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

/// Creates a tar archive containing a single file
/// - Parameters:
/// - data: The file's body data
/// - filename: The file's name in the archive
/// - Returns: A tar archive containing the file
/// - Throws: If the filename is invalid
public func tar(_ data: Data, filename: String) throws -> [UInt8] {
try tar([UInt8](data), filename: filename)
}

/// Represents a tar archive
public struct Archive {
/// The files, directories and other members of the archive
Expand Down
2 changes: 1 addition & 1 deletion Sources/containertool/containertool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ enum AllowHTTP: String, ExpressibleByArgument, CaseIterable { case source, desti
// MARK: Build the application layer

let payload_name = executableURL.lastPathComponent
let tardiff = try tar(payload, filename: payload_name)
let tardiff = try tar([UInt8](payload), filename: payload_name)
log("Built application layer")

// MARK: Upload the application layer
Expand Down