From de371d3b8c49034c32fb9010eb295742c952b8b9 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Mon, 6 May 2024 19:02:28 +0200 Subject: chroottar.py: implement Tarfile.zstopen for fileobj zstandard.open actually consumes file objects. Hence there is little benefit in not implementing the passing of a fileobj even though we don't use it here. --- examples/chroottar.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/chroottar.py b/examples/chroottar.py index d229956..49d9a7d 100755 --- a/examples/chroottar.py +++ b/examples/chroottar.py @@ -31,12 +31,11 @@ class TarFile(tarfile.TarFile): cls, name: str, mode: typing.Literal["r", "w", "x"] = "r", - fileobj: None = None, + fileobj: typing.BinaryIO | None = None, ) -> tarfile.TarFile: if mode not in ("r", "w", "x"): raise NotImplementedError(f"mode `{mode}' not implemented for zst") - if fileobj is not None: - raise NotImplementedError("zst does not support a fileobj") + openobj: str | typing.BinaryIO = name if fileobj is None else fileobj try: import zstandard except ImportError as err: @@ -44,10 +43,10 @@ class TarFile(tarfile.TarFile): "zstandard module not available" ) from err if mode == "r": - zfobj = zstandard.open(name, "rb") + zfobj = zstandard.open(openobj, "rb") else: zfobj = zstandard.open( - name, + openobj, mode + "b", cctx=zstandard.ZstdCompressor(write_checksum=True, threads=-1), ) -- cgit v1.2.3