Skip to content

Commit 0ac48ae

Browse files
committed
[docs] Add documentation for TarContainer.create(from:force:)
1 parent 4e8be1d commit 0ac48ae

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

Sources/TAR/Data+Tar.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ extension Data {
5353
/// This should work in the same way as `String.padding(toLength: length, withPad: "\0", startingAt: 0)`.
5454
@inline(__always)
5555
private func zeroPad(_ length: Int) -> Data {
56-
// TODO: Maybe this should modify self
5756
var out = length < self.count ? self.prefix(upTo: length) : self
5857
out.append(Data(count: length - out.count))
5958
return out

Sources/TAR/TarContainer.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,24 @@ public class TarContainer: Container {
8383
return create(from: entries, force: .pax)
8484
}
8585

86-
public static func create(from entries: [TarEntry], force format: TarContainer.Format) -> Data {
86+
/**
87+
Creates a new TAR container with `entries` as its content and generates its `Data` using the specified `format`.
88+
89+
This function forces the usage of the `format`, meaning that certain properties about the `entries` may be missing
90+
from the resulting container data if the chosen format doesn't support certain features. For example, relatively
91+
long names (and linknames) will be truncated if the `.ustar` or `.prePosix` format is specified.
92+
93+
It is highly recommended to use the `TarContainer.create(from:)` function (or use the `.pax` format) to ensure the
94+
best representation of the `entries` in the output. Other (non-PAX) formats should only be used if you have a
95+
specific need for them and you understand limitations of those formats.
96+
97+
- Parameter entries: TAR entries to store in the container.
98+
- Parameter force: For the usage of the specified format.
99+
100+
- SeeAlso: `TarEntryInfo` properties documenation to see how their values are connected with the specific TAR
101+
format used during container creation.
102+
*/
103+
public static func create(from entries: [TarEntry], force format: TarContainer.Format) -> Data {
87104
// The general strategy is as follows. For each entry we:
88105
// 1. Create special entries if required by the entry's info and if supported by the format.
89106
// 2. For each special entry we create a TarHeader.

Sources/TAR/TarHeader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct TarHeader {
157157
init(_ info: TarEntryInfo) {
158158
self.name = info.name
159159
self.type = .normal(info.type)
160-
self.size = info.size ?? 0 // TODO: tarInt(...) may not work as expected for 0 instead of nil.
160+
self.size = info.size ?? 0
161161
self.atime = info.accessTime
162162
self.ctime = info.creationTime
163163
self.mtime = info.modificationTime

0 commit comments

Comments
 (0)