tarfile : read from a socket?

Lars Gustäbel lars at gustaebel.de
Thu Feb 11 12:27:28 EST 2016


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,

-- 
Lars Gustäbel
lars at gustaebel.de



More information about the Python-list mailing list