Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Lars =?iso-8859-1?Q?Gust=E4bel?= Newsgroups: comp.lang.python Subject: Re: tarfile : read from a socket? Date: Fri, 12 Feb 2016 09:40:38 +0100 Lines: 23 Message-ID: References: <20160211172728.GA27743@axis.g33x.de> <56BD995C.1030600@rece.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de YrJnPnpAvlFPRyWn3GVkuAwj2iYcZXTaWhHMXdWSm27Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.035 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'cc:addr:python-list': 0.09; 'def': 0.13; '2016': 0.16; 'iterator.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'tarfile': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'cc:no real name:2**0': 0.22; 'bit': 0.23; 'feb': 0.23; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'fri,': 0.27; 'skip:t 40': 0.27; 'yield': 0.27; 'print': 0.30; 'subject: : ': 0.30; 'url:python': 0.33; 'i.e.': 0.35; 'url:org': 0.36; 'url:library': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'setting': 0.37; '12,': 0.37; 'received:88.198': 0.37; 'does': 0.39; 'subject:from': 0.39; 'received:192': 0.39; 'received:de': 0.40; 'url:3': 0.60; 'more': 0.63; 'pardon': 0.84; 'subject:read': 0.84 Mail-Followup-To: Lars =?iso-8859-1?Q?Gust=E4bel?= , Antoon Pardon , python-list@python.org Content-Disposition: inline In-Reply-To: <56BD995C.1030600@rece.vub.ac.be> User-Agent: Mutt/1.5.23 (2014-03-12) X-Virus-Scanned: clamav-milter 0.98.7 at tera X-Virus-Status: Clean X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102856 On Fri, Feb 12, 2016 at 09:35:40AM +0100, Antoon Pardon wrote: > On 02/11/2016 06:27 PM, Lars Gustäbel wrote: > > 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) > > > The tarfile is already an iterator. Just do the following: for ti in > taro: print "extracting", ti.name taro.extract(ti) The extractall() method does a little bit more than just extract(), i.e. setting directory mtimes, see https://docs.python.org/3.5/library/tarfile.html#tarfile.TarFile.extractall -- Lars Gustäbel lars@gustaebel.de