From 46bf2a6d9459e7ac05eccc018fb05f8ff51ef9ea Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Wed, 11 Jul 2018 20:59:48 +0300 Subject: [PATCH] [TAR] Add fileprivate extension to Data which works like String.padding and Data.prefix combined --- Sources/TAR/TarEntryInfo.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/TAR/TarEntryInfo.swift b/Sources/TAR/TarEntryInfo.swift index e1de9da7..4e519f96 100644 --- a/Sources/TAR/TarEntryInfo.swift +++ b/Sources/TAR/TarEntryInfo.swift @@ -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 + } + +}