MCPcopy Index your code
hub / github.com/RustPython/RustPython / zstopen

Method zstopen

Lib/tarfile.py:2048–2080  ·  view source on GitHub ↗

Open zstd compressed tar archive name for reading or writing. Appending is not allowed.

(cls, name, mode="r", fileobj=None, level=None, options=None,
                zstd_dict=None, **kwargs)

Source from the content-addressed store, hash-verified

2046
2047 @classmethod
2048 def zstopen(cls, name, mode="r", fileobj=None, level=None, options=None,
2049 zstd_dict=None, **kwargs):
2050 """Open zstd compressed tar archive name for reading or writing.
2051 Appending is not allowed.
2052 """
2053 if mode not in ("r", "w", "x"):
2054 raise ValueError("mode must be 'r', 'w' or 'x'")
2055
2056 try:
2057 from compression.zstd import ZstdFile, ZstdError
2058 except ImportError:
2059 raise CompressionError("compression.zstd module is not available") from None
2060
2061 fileobj = ZstdFile(
2062 fileobj or name,
2063 mode,
2064 level=level,
2065 options=options,
2066 zstd_dict=zstd_dict
2067 )
2068
2069 try:
2070 t = cls.taropen(name, mode, fileobj, **kwargs)
2071 except (ZstdError, EOFError) as e:
2072 fileobj.close()
2073 if mode == 'r':
2074 raise ReadError("not a zstd file") from e
2075 raise
2076 except Exception:
2077 fileobj.close()
2078 raise
2079 t._extfileobj = False
2080 return t
2081
2082 # All *open() methods are registered here.
2083 OPEN_METH = {

Callers

nothing calls this directly

Calls 5

closeMethod · 0.95
ZstdFileClass · 0.90
CompressionErrorClass · 0.85
taropenMethod · 0.80
ReadErrorClass · 0.70

Tested by

no test coverage detected