On Thu, Oct 8, 2009 at 4:10 PM, xbmuncher <xboxmunc...@gmail.com> wrote:
> 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?

I think tarfile.extractfile() does what you want. The docs are a bit
confusing but it returns a file-like object from which the item can be
read. Your code would be something like

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

for tarInfo in tar:
  putThisDataSomewhere(tar.extractfile(tarInfo))

putThisDataSomewhere() will read from its argument and write to FTP.
Any required blocking or buffering would be in putThisDataSomewhere().

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

Reply via email to