I have a large tar.bz2 file that I want to extract certain files directly to an FTP path. <br>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.<br>
Is there a way to do this?<br>Here's my pseudocode:<br><br>import tarfile<br><br>def putThisDataSomewhere(data):<br> #write it to a file in FTP<br><br><br>tar = tarfile.open("HUGE_FILE_OVER_5GB.tar.bz2", "r:bz2")<br>
readSize = 50<br><br>for tarInfo in tar:<br> fileSize = tarInfo.size<br> <br> #prepare for loop to read specific file inside tar<br> if readSize > fileSize<br> readSize = fileSize<br> readIterations = fileSize/readSize<br>
<br> #loop & read file<br> for i in range(readIterations):<br> putThisDataSomewhere(tarFile.read(readSize))<br> <br> #catch remainder of file<br> lastReadSize = fileSize - (readSize * readIterations)<br>
if lastReadSize:<br> putThisDataSomewhere(tarFile.read(lastReadSize))<br> <br> <br> <br>tar.close()<br>