2
# The Python Imaging Library.
5
# read files from within a tar file
9
# 96-05-28 fl Open files in binary mode
11
# Copyright (c) Secret Labs AB 1997.
12
# Copyright (c) Fredrik Lundh 1995-96.
14
# See the README file for information on usage and redistribution.
21
# A file object that provides read access to a given member of a TAR
24
class TarIO(ContainerIO.ContainerIO):
29
# @param tarfile Name of TAR file.
30
# @param file Name of member file.
32
def __init__(self, tarfile, file):
34
fh = open(tarfile, "rb")
40
raise IOError, "unexpected end of tar file"
43
i = string.find(name, chr(0))
45
raise IOError, "cannot find subfile"
49
size = string.atoi(s[124:136], 8)
54
fh.seek((size + 511) & (~511), 1)
57
ContainerIO.ContainerIO.__init__(self, fh, fh.tell(), size)