[TAR] Apply base-256 encoding to negative values as well

This commit is contained in:
Timofey Solomko
2018-07-31 18:56:18 +03:00
parent feafb419f5
commit bf96273ea8
2 changed files with 2 additions and 4 deletions
+1 -3
View File
@@ -22,9 +22,7 @@ extension ByteReader {
*/
func tarCString(maxLength: Int) -> String {
var buffer = self.bytes(count: maxLength)
guard !buffer.isEmpty
else { return "" }
if buffer.last! != 0 {
if buffer.last != 0 {
buffer.append(0)
}
return buffer.withUnsafeBufferPointer { String(cString: $0.baseAddress!) }
+1 -1
View File
@@ -361,7 +361,7 @@ fileprivate extension Data {
}
let maxOctalValue = (1 << (maxLength * 3)) - 1
guard value > maxOctalValue else {
guard value > maxOctalValue || value < 0 else {
// Normal octal encoding.
self.append(String(value, radix: 8).data(using: .utf8)!.zeroPad(maxLength))
return