tarfile : read from a socket?
Antoon Pardon
antoon.pardon at rece.vub.ac.be
Fri Feb 12 03:35:40 EST 2016
On 02/11/2016 06:27 PM, Lars Gustäbel wrote:
> On Thu, Feb 11, 2016 at 04:41:43PM +0000, Ulli Horlacher wrote:
>> sfo = sock.makefile('r')
>> taro = tarfile.open(fileobj=sfo,mode='r|')
>> taro.extractall(path=edir)
> 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)
>
> Cheers,
The tarfile is already an iterator. Just do the following: for ti in
taro: print "extracting", ti.name taro.extract(ti)
More information about the Python-list
mailing list