diff --git a/tar.py b/tar.py index 5e2b640..0394bcc 100644 --- a/tar.py +++ b/tar.py @@ -37,11 +37,11 @@ def header_chunk(filename: str, filepath: str) -> bytes: buffer += '0001000'.encode('ascii') + b'\x00' # 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 # 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 buffer += ' '.encode('ascii') @@ -56,7 +56,7 @@ def header_chunk(filename: str, filepath: str) -> bytes: buffer += b'\x00' * 255 # 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 return bytes(buffer)