def xzopen(cls, name, mode="r", fileobj=None, compresslevel=6):
"""
Open xz compressed cpio archive name for reading or writing.
Appending is not allowed.
"""
if len(mode) > 1 or mode not in "rw":
raise ValueError("mode must be 'r' or 'w'.")
try:
import lzma
except ImportError:
raise CompressionError("lzma module is not available")
if fileobj is not None:
fileobj = _XZProxy(fileobj, mode)
else:
fileobj = lzma.LZMAFile(name, mode) # options={'level': compresslevel, 'dict_size': 20 }
try:
t = cls.cpioopen(name, mode, fileobj)
except IOError:
raise ReadError("not a XZ file")
t._extfileobj = False
return t
# All *open() methods are registered here.
评论列表
文章目录