Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102806

Re: tarfile : read from a socket?

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: tarfile : read from a socket?
Date 2016-02-12 00:18 +1100
Message-ID <mailman.48.1455196694.22075.python-list@python.org> (permalink)
References <n9hgtb$rls$1@news2.informatik.uni-stuttgart.de> <mailman.43.1455187713.22075.python-list@python.org> <n9i07l$vgl$1@news2.informatik.uni-stuttgart.de>

Show all headers | View raw


On Thu, Feb 11, 2016 at 11:53 PM, Ulli Horlacher
<framstag@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

tarfile : read from a socket? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-02-11 08:31 +0000
  Re: tarfile : read from a socket? INADA Naoki <songofacandy@gmail.com> - 2016-02-11 19:26 +0900
  Re: tarfile : read from a socket? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-02-11 11:47 +0100
    Re: tarfile : read from a socket? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-02-11 12:53 +0000
      Re: tarfile : read from a socket? MRAB <python@mrabarnett.plus.com> - 2016-02-11 13:16 +0000
      Re: tarfile : read from a socket? Chris Angelico <rosuav@gmail.com> - 2016-02-12 00:18 +1100
        Re: tarfile : read from a socket? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-02-11 13:34 +0000
      Re: tarfile : read from a socket? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-02-11 13:25 +0000
        Re: tarfile : read from a socket? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-02-11 16:41 +0000
          Re: tarfile : read from a socket? MRAB <python@mrabarnett.plus.com> - 2016-02-11 17:10 +0000
          modifying a standard module? (was: Re: tarfile : read from a socket?) Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-02-11 17:10 +0000
            Re: modifying a standard module? (was: Re: tarfile : read from a socket?) Matt Wheeler <m@funkyhat.org> - 2016-02-12 20:53 +0000
              Re: modifying a standard module? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-02-12 22:46 +0000
                Re: modifying a standard module? Paul Rubin <no.email@nospam.invalid> - 2016-02-12 16:21 -0800
          Re: tarfile : read from a socket? Peter Otten <__peter__@web.de> - 2016-02-11 18:18 +0100
          Re: tarfile : read from a socket? Lars Gustäbel <lars@gustaebel.de> - 2016-02-11 18:27 +0100
          Re: tarfile : read from a socket? Random832 <random832@fastmail.com> - 2016-02-11 16:23 -0500
          Re: tarfile : read from a socket? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-02-12 09:35 +0100
          Re: tarfile : read from a socket? Lars Gustäbel <lars@gustaebel.de> - 2016-02-12 09:40 +0100
            Re: tarfile : read from a socket? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-02-12 12:48 +0000

csiph-web