Berion
Developer
Any Python 3 magician on a forum? I have some script made by ChatGPT
but I don't know how to fix it. What I wanted to do is skipping first 16 bytes and strip all the next reading chunks by 2352 bytes from 2352 to 2336 bytes only (which means, converting entire disc image). I could do that in bash but somehow this interested me and I cannot found solution myself.
I don't see any sense in first def thou. Interpreter returns: NameError: name 'chunk_size' is not defined
I don't see any sense in first def thou. Interpreter returns: NameError: name 'chunk_size' is not defined
Code:
input_filename = '2352.bin'
output_filename = '2336.bin'
def extract_data(input_filename, output_filename):
chunk_size = 2352
extract_size = 2336
offset = 16
with open(input_filename, 'rb') as input_file, open(output_filename, 'wb') as output_file:
while True:
chunk = input_file.read(chunk_size)
if not chunk:
break
if len(chunk) < chunk_size:
break
extracted_data = chunk[offset:offset+extract_size]
output_file.write(extracted_data)
if __name__ == '__main__':
extract_data(input_filename, output_filename)
print(f"Data extracted from {input_filename} and saved to {output_filename}")

