mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
[TAR] Apply base-256 encoding to negative values as well
This commit is contained in:
@@ -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!) }
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user