This commit is contained in:
Thomas Forgione 2024-07-23 14:31:55 +02:00
parent 762900e1f1
commit b5e985cd86
1 changed files with 3 additions and 3 deletions

6
tar.py
View File

@ -37,11 +37,11 @@ def header_chunk(filename: str, filepath: str) -> bytes:
buffer += '0001000'.encode('ascii') + b'\x00' buffer += '0001000'.encode('ascii') + b'\x00'
# Field 5: file size in bytes in ascii # Field 5: file size in bytes in ascii
buffer += str(stat.st_size).rjust(11, '0').encode('ascii') + b'\x00' buffer += oct(stat.st_size)[2:].rjust(11, '0').encode('ascii') + b'\x00'
# Field 6: last modified, zeros for now # Field 6: last modified, zeros for now
# buffer += '00000000000'.encode('ascii') + b'\x00' # buffer += '00000000000'.encode('ascii') + b'\x00'
buffer += '1721728914'.rjust(11, '0').encode('ascii') + b'\x00' buffer += oct(1721728914)[2:].rjust(11, '0').encode('ascii') + b'\x00'
# Field 7: checksum, we put spaces and we will edit it at the end # Field 7: checksum, we put spaces and we will edit it at the end
buffer += ' '.encode('ascii') buffer += ' '.encode('ascii')
@ -56,7 +56,7 @@ def header_chunk(filename: str, filepath: str) -> bytes:
buffer += b'\x00' * 255 buffer += b'\x00' * 255
# Compute the checksum # Compute the checksum
checksum = str(functools.reduce(lambda x, y: x + y, buffer)).rjust(6, '0').encode('ascii') + b'\x00 ' checksum = oct(functools.reduce(lambda x, y: x + y, buffer))[2:].rjust(6, '0').encode('ascii') + b'\x00 '
buffer[148:156] = checksum buffer[148:156] = checksum
return bytes(buffer) return bytes(buffer)