chunksize = 64*1024 #arbitrary number
offset = 0
with open(path, 'r+b') as file:
while True:
file.seek(chunksize*offset) # sets pointer to reading spot
chunk = file.read(chunksize)
if len(chunk) == 0: # checks if EoF
break
elif len(chunk) % 16 != 0: # adds bytes to the chunk if it is the last chunk and size doesnt divide by 16 (if processing text of specific size, my case 16 bytes)
chunk += ' ' * (16 - len(chunk) % 16)
file.seek(chunksize*offset) # returns pointer to beginning of the chunk in order to rewrite the data that was encrypted
file.write(do_something(chunk)) # edits and writes data to file
offset += 1
以下代码应起作用:
代码读取数据,返回到块的开头并覆盖它。如果操作的数据大于读取的数据,它将不起作用。他说
相关问题 更多 >
编程相关推荐