I need to generate the tar.gz (or tar.bz2) archive in Python, where contents of each file is generated "on the fly". The ideal solution should look as follows:
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()
I now, that it can be done by creating files on disk and adding them later on. But due to insufficient storage space, I have to compress data on the fly, and additionally I want to have them placed in a single compressed tar archive.