I have a large tar.bz2 file that I want to extract certain files directly to
an FTP path.
Since the extract() method doesn't accept ftp paths...  I wanted to read the
files from the tar file like a file object or file I/O stream.
Is there a way to do this?
Here's my pseudocode:

import tarfile

def putThisDataSomewhere(data):
    #write it to a file in FTP


tar = tarfile.open("HUGE_FILE_OVER_5GB.tar.bz2", "r:bz2")
readSize = 50

for tarInfo in tar:
    fileSize = tarInfo.size

    #prepare for loop to read specific file inside tar
    if readSize > fileSize
        readSize = fileSize
    readIterations = fileSize/readSize

    #loop & read file
    for i in range(readIterations):
        putThisDataSomewhere(tarFile.read(readSize))

    #catch remainder of file
    lastReadSize = fileSize - (readSize * readIterations)
    if lastReadSize:
        putThisDataSomewhere(tarFile.read(lastReadSize))



tar.close()
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to