def __init__(self, name, mode, comptype, fileobj, bufsize,
concat_stream=False, enctype='', password="",
- key_length=128):
+ key_length=128, compresslevel=9):
"""Construct a _Stream object.
"""
self._extfileobj = True
self.dbuf = b""
self.aes_buf = b""
self.exception = None
+ self.compresslevel = compresslevel
try:
if comptype == "gz":
def _init_write_gz(self):
"""Initialize for writing with gzip compression.
"""
- self.cmp = self.zlib.compressobj(9, self.zlib.DEFLATED,
- -self.zlib.MAX_WBITS,
- self.zlib.DEF_MEM_LEVEL,
- 0)
+ self.cmp = self.zlib.compressobj(self.compresslevel,
+ self.zlib.DEFLATED,
+ -self.zlib.MAX_WBITS,
+ self.zlib.DEF_MEM_LEVEL,
+ 0)
# if aes, we encrypt after compression
if self.enctype == 'aes':
self.closed = False
self.concat_pos = 0
self.crc = self.zlib.crc32(b"")
- self.cmp = self.zlib.compressobj(9, self.zlib.DEFLATED,
- -self.zlib.MAX_WBITS,
- self.zlib.DEF_MEM_LEVEL,
- 0)
+ self.cmp = self.zlib.compressobj(self.compresslevel,
+ self.zlib.DEFLATED,
+ -self.zlib.MAX_WBITS,
+ self.zlib.DEF_MEM_LEVEL,
+ 0)
# if aes, we encrypt after compression
if self.enctype == 'aes':
# by adding it to the mapping in OPEN_METH.
@classmethod
- def open(cls, name=None, mode="r", fileobj=None, bufsize=RECORDSIZE, **kwargs):
+ def open(cls, name=None, mode="r", fileobj=None, bufsize=RECORDSIZE,
+ compresslevel=9, **kwargs):
"""Open a tar archive for reading, writing or appending. Return
an appropriate TarFile class.
func = getattr(cls, cls.OPEN_METH[comptype])
else:
raise CompressionError("unknown compression type %r" % comptype)
- return func(name, filemode, fileobj, **kwargs)
+ return func(name, filemode, fileobj, compresslevel, **kwargs)
elif "|" in mode:
filemode, comptype = mode.split("|", 1)
raise ValueError("mode must be 'r' or 'w'")
t = cls(name, filemode,
- _Stream(name, filemode, comptype, fileobj, bufsize),
+ _Stream(name, filemode, comptype, fileobj, bufsize,
+ compresslevel=compresslevel),
**kwargs)
t._extfileobj = False
return t
stream = _Stream(name, filemode, comptype, fileobj, bufsize,
concat_stream=True, enctype=enctype,
- password=password, key_length=key_length)
+ password=password, key_length=key_length,
+ compresslevel=compresslevel)
try:
t = cls(name, filemode, stream, **kwargs)
except: