tarfile : read from a socket?
MRAB
python at mrabarnett.plus.com
Thu Feb 11 12:10:16 EST 2016
On 2016-02-11 16:41, Ulli Horlacher wrote:
> Ulli Horlacher <framstag at rus.uni-stuttgart.de> wrote:
>
>> With
>>
>> taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w|')
>>
>> I get no more error.
>
> Of course, this is the writing client.
>
> Now I have a small problem with the reading client.
>
> This code works so far:
>
> sfo = sock.makefile('r')
> taro = tarfile.open(fileobj=sfo,mode='r|')
> taro.extractall(path=edir)
>
> But it does not writes anything to the terminal to inform the user.
>
> When I use:
>
> for member in taro.getmembers():
> print('extracting "%s"' % member.name)
> taro.extract(member)
>
> I get the error:
>
> File "/usr/lib/python2.7/tarfile.py", line 556, in seek
> raise StreamError("seeking backwards is not allowed")
>
> Of course, a stream is not seekable.
>
> Any ideas?
>
Try this:
member = taro.next()
while member is not None:
print('extracting "%s"' % member.name)
taro.extract(member)
member = tar.next()
More information about the Python-list
mailing list