summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2024-05-06 19:02:28 +0200
committerHelmut Grohne <helmut@subdivi.de>2024-05-06 19:02:28 +0200
commitde371d3b8c49034c32fb9010eb295742c952b8b9 (patch)
tree37d5e23945d3a89a460b0ee049ca9b5a4e78762e /examples
parente42cc93582ce11f53f7336abcacff4681699384d (diff)
downloadpython-linuxnamespaces-de371d3b8c49034c32fb9010eb295742c952b8b9.tar.gz
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.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/chroottar.py9
1 files changed, 4 insertions, 5 deletions
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),
)