[TAR] Add fileprivate extension to Data which works like String.padding and Data.prefix combined

This commit is contained in:
Timofey Solomko
2018-07-29 18:04:19 +03:00
parent 2e40dc903a
commit 46bf2a6d94
+12
View File
@@ -255,3 +255,15 @@ public struct TarEntryInfo: ContainerEntryInfo {
}
}
fileprivate extension Data {
/// This works (hopefully) in the same way as `String.padding(toLength: length, withPad: "\0", startingAt: 0)`.
@inline(__always)
private func zeroPad(_ length: Int) -> Data {
var out = length < self.count ? self.prefix(upTo: length) : self
out.append(Data(count: length - out.count))
return out
}
}