tarfile : read from a socket?
Chris Angelico
rosuav at gmail.com
Thu Feb 11 08:18:04 EST 2016
On Thu, Feb 11, 2016 at 11:53 PM, Ulli Horlacher
<framstag at rus.uni-stuttgart.de> wrote:
> I have:
>
> sock = socket.create_connection((server,port))
> bs = kB64
> taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
>
>
>
> Traceback (most recent call last):
> (...)
> File "./fexit.py", line 1838, in sex_send
> taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
> File "/usr/lib/python2.7/tarfile.py", line 1695, in open
> return cls.taropen(name, mode, fileobj, **kwargs)
> File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
> return cls(name, mode, fileobj, **kwargs)
> File "/usr/lib/python2.7/tarfile.py", line 1566, in __init__
> self.offset = self.fileobj.tell()
> AttributeError: '_fileobject' object has no attribute 'tell'
Sounds like tarfile needs a seekable file. How big is this file you're
reading? Can you simply read the whole thing into memory, then use
io.BytesIO? I had a quick glance at help(BytesIO) but didn't find a
simple way to make a buffer that reads from an upstream file when it
needs more content, but it should be possible to build one.
ChrisA
More information about the Python-list
mailing list