tarfile : read from a socket?

Ulli Horlacher framstag at rus.uni-stuttgart.de
Fri Feb 12 07:48:30 EST 2016


Lars Gustäbel <lars at gustaebel.de> wrote:
> On Fri, Feb 12, 2016 at 09:35:40AM +0100, Antoon Pardon wrote:
> > On 02/11/2016 06:27 PM, Lars Gustäbel wrote:
> > > What about using an iterator?
> > >
> > > def myiter(tar):
> > >     for t in tar:
> > >         print "extracting", t.name
> > >         yield t
> > >
> > > sfo = sock.makefile('r')
> > > taro = tarfile.open(fileobj=sfo,mode='r|')
> > > taro.extractall(members=myiter(taro),path=edir)
> > >
> > The tarfile is already an iterator. Just do the following: for ti in
> > taro:     print "extracting", ti.name taro.extract(ti)
> 
> The extractall() method does a little bit more than just extract(), i.e.
> setting directory mtimes, see
> https://docs.python.org/3.5/library/tarfile.html#tarfile.TarFile.extractall

This is an important hint!
Thanks!


-- 
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum IZUS/TIK         E-Mail: horlacher at tik.uni-stuttgart.de
Universitaet Stuttgart         Tel:    ++49-711-68565868
Allmandring 30a                Fax:    ++49-711-682357
70550 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de/


More information about the Python-list mailing list