2

我需要在 Python 中生成 tar.gz(或 tar.bz2)存档,其中每个文件的内容都是“即时”生成的。理想的解决方案应如下所示:

import hypothetic_extended_tar_lib as tl
tf1=tl.open("myarchive.tar.bz2",mode="wb")
df1=tf1.newfile("file1.bin")
#Now get data from the DAQ1
for rec_num in xrange(1,1000):
   data=daq1.get_data(rec_num)
   df1.write(data)
df1.close()
df2=tf1.newfile("file2.bin")
#Get some data from the second DAq
for rec_num in xrange(1,500):
   data=daq2.get_data(rec_num)
   df2.write(data)
df2.close()
tf1.close()

我现在,可以通过在磁盘上创建文件并稍后添加它们来完成。但是由于存储空间不足,我必须即时压缩数据,另外我希望将它们放在一个压缩的 tar 存档中。

4

0 回答 0