我有一个非常大的存档文件(~11 GB)。我想用更大的文件替换该档案中的文件(我知道格式我不会有任何问题)。 问题是,如果有任何有效的方法可以做到这一点。
我目前的方式是使用此代码:
f=open('big_archive','r+b') #open big archive
#Store data after the file
tail=open('temp_file_for_storing_rest_data','wb')
f.seek(correct_offset+old_file_size)
buf=1
while buf:
buf=f.read(1024*1024*1024) #writing 1GB parts at a time
tail.write(buf)
tail.close()
f.write(my_file_bytes) # write my file
#Append the tail back to the file
tail=open('temp_file_for_storing_rest_data','rb')
buf=1
while buf:
buf=tail.read(1024*1024*1024) #reading 1GB parts at a time
f.write(buf)
f.close()
有什么方法可以避免这种磁盘读写混乱?
编辑:在尝试将部件尺寸增加到2GB时,我也遇到了一些问题。当程序试图将大小强制转换为C Long时,我得到了一个错误的错误。