[New-bugs-announce] [issue11458] tarfile with socket incompatability

Alex Leach report at bugs.python.org
Thu Mar 10 03:33:59 CET 2011

New submission from Alex Leach <beamesleach at gmail.com>:


I'm trying to parse the contents of tar archives (.tgz) on the fly, and failing to do so. The tar archives in question have directory hierarchies, and only if a TarInfo object is a file (.isreg() ) will I try and read it's contents.

I figured a sensible idea would be to pass a socket(.makefile()) object to the fileobj attribute of tarfile.open. This doesn't work because a socket file descriptor does not have a tell() method. I understand that a socket object shouldn't need to have a tell method, but why should the fileobj passed to tarfile.open need it?


def get_headers( self, file_name ):
    sock = socket.socket()
    fd = sock.makefile()
    handle = tarfile.open( file_name,'r',fileobj=fd ) # This line breaks

I'm currently testing on Python v2.6.6 EPD 6.3-2 64 bit, on an Autumn 2010 Mac Pro.

My dirty bug-fix idea is to subclass tarfile.TarFile, and give it a tell() method, to just return 0. I don't want to have to do that. Any alternative suggestions would be greatly appreciated.


components: Extension Modules
messages: 130482
nosy: Alex.Leach
priority: normal
severity: normal
status: open
title: tarfile with socket incompatability

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list