comptype = 'tar'
sink = tarfile._Stream(name=path, mode=mode, comptype=comptype,
- concat_stream=True, # no global zlib header
bufsize=tarfile.RECORDSIZE, fileobj=None,
- encryption=self.crypto_ctx)
+ encryption=self.crypto_ctx, noinit=True)
if self.crypto_ctx is not None and mode == "w":
counter = None
if kind == AUXILIARY_FILE_INFO:
remainder = -1 # track size in encrypted entries
def __init__(self, name, mode, comptype, fileobj, bufsize,
- concat_stream=False, encryption=None, compresslevel=9):
+ concat_stream=False, encryption=None, compresslevel=9,
+ noinit=False):
"""Construct a _Stream object.
"""
self._extfileobj = True
except ImportError:
raise CompressionError("zlib module is not available")
self.zlib = zlib
- if concat_stream is False:
- if mode == "r":
+ if mode == "r":
+ self.exception = zlib.error
+ if concat_stream is True:
self._init_read_gz()
- elif mode == "w":
+ elif mode == "w":
+ if noinit is False:
self._new_gz_block()
self.crc = zlib.crc32(b"") & 0xFFFFffff
- if mode == "r":
- self.exception = zlib.error
elif comptype == "bz2":
if self.encryption is not None:
'r#gz' open a stream of gzip compressed tar blocks for reading
'w#gz' open a stream of gzip compressed tar blocks for writing
"""
-
if not name and not fileobj:
raise ValueError("nothing to open")
if filemode not in "rw":
raise ValueError("mode must be 'r' or 'w'")
- kwargs['concat_compression'] = True
-
stream = _Stream(name, filemode, comptype, fileobj, bufsize,
concat_stream=True, encryption=encryption,
compresslevel=compresslevel)
+ kwargs ["concat_compression"] = True
try:
t = cls(name, filemode, stream, **kwargs)
except: # XXX except what?