we are trapped in the tar (i made it 1ms faster yay for me the ratboy genius)

This commit is contained in:
2024-11-12 18:41:20 +11:00
parent cee34c6f7a
commit 3e47d6cd01

View File

@ -36,15 +36,13 @@ public struct TarReader {
let size = try Self.readSize(tarBlock) let size = try Self.readSize(tarBlock)
// Read file data // Read file data
var data = Data(count: size) var data = Data()
if size > 0 { if size > 0 {
try data.withUnsafeMutableBytes { data = try stream.read(size)
guard size == (try stream.read( guard size == data.count else {
$0.baseAddress!.assumingMemoryBound(to: UInt8.self), throw TarError.unexpectedEndOfStream
maxLength: size)) else {
throw TarError.unexpectedEndOfStream
}
} }
// Seek to next block boundry // Seek to next block boundry
let blockN1 = Self.tarBlockSize - 1 let blockN1 = Self.tarBlockSize - 1
let seekAmount = blockN1 - ((size + blockN1) % Self.tarBlockSize) // 511 ((size 1) & 0x1FF) let seekAmount = blockN1 - ((size + blockN1) % Self.tarBlockSize) // 511 ((size 1) & 0x1FF)