def test_decompress_copy(): """ inflateCopy produces an independent copy of a stream. """ stream = rzlib.inflateInit() bytes1, finished1, unused1 = rzlib.decompress(stream, compressed[:10]) assert bytes1 assert finished1 is False copied = rzlib.inflateCopy(stream) bytes_stream, finished_stream, unused_stream = rzlib.decompress( stream, compressed[10:], rzlib.Z_FINISH, ) assert bytes1 + bytes_stream == expanded assert finished_stream is True assert unused1 == 0 assert unused_stream == 0 rzlib.inflateEnd(stream) bytes_copy, finished_copy, unused_copy = rzlib.decompress( copied, compressed[10:], rzlib.Z_FINISH, ) rzlib.inflateEnd(copied) assert bytes1 + bytes_copy == expanded assert finished_copy is True assert unused_copy == 0
def copy(self, space): """ copy() -- Return a copy of the decompression object. """ try: self.lock() try: if not self.stream: raise oefmt( space.w_ValueError, "Decompressor was already flushed", ) copied = rzlib.inflateCopy(self.stream) finally: self.unlock() except rzlib.RZlibError as e: raise zlib_error(space, e.msg) return Decompress( space=space, stream=copied, unused_data=self.unused_data, unconsumed_tail=self.unconsumed_tail, zdict=self.zdict, )
def copy(self, space): """ copy() -- Return a copy of the decompression object. """ try: self.lock() try: copied = rzlib.inflateCopy(self.stream) finally: self.unlock() except rzlib.RZlibError as e: raise zlib_error(space, e.msg) return Decompress( space=space, stream=copied, unused_data=self.unused_data, unconsumed_tail=self.unconsumed_tail, )