This commit is contained in:
Iliyan Angelov
2025-12-01 06:50:10 +02:00
parent 91f51bc6fe
commit 62c1fe5951
4682 changed files with 544807 additions and 31208 deletions

View File

@@ -13,16 +13,17 @@
#
# See the README file for information on usage and redistribution.
#
from __future__ import annotations
import io
from . import ContainerIO
class TarIO(ContainerIO.ContainerIO):
class TarIO(ContainerIO.ContainerIO[bytes]):
"""A file object that provides read access to a given member of a TAR file."""
def __init__(self, tarfile, file):
def __init__(self, tarfile: str, file: str) -> None:
"""
Create file object.
@@ -34,12 +35,16 @@ class TarIO(ContainerIO.ContainerIO):
while True:
s = self.fh.read(512)
if len(s) != 512:
self.fh.close()
msg = "unexpected end of tar file"
raise OSError(msg)
name = s[:100].decode("utf-8")
i = name.find("\0")
if i == 0:
self.fh.close()
msg = "cannot find subfile"
raise OSError(msg)
if i > 0:
@@ -54,13 +59,3 @@ class TarIO(ContainerIO.ContainerIO):
# Open region
super().__init__(self.fh, self.fh.tell(), size)
# Context manager support
def __enter__(self):
return self
def __exit__(self, *args):
self.close()
def close(self):
self.fh.close()