class PpmdCompressor(ISevenZipCompressor): """Compress with PPMd compression algorithm""" def __init__(self, level: int, mem: int, blocksize: Optional[int] = None): self._buf = BufferedRW(blocksize) self.encoder = Ppmd.Ppmd7Encoder(self._buf, level, mem) # type: ignore def compress(self, data: Union[bytes, bytearray, memoryview]) -> bytes: self.encoder.encode(data) return self._buf.read() def flush(self): self.encoder.flush() return self._buf.read()
class PpmdCompressor(ISevenZipCompressor): def __init__(self, level: int, mem: int): if Ppmd is None: raise UnsupportedCompressionMethodError self._buf = BufferedRW() self.encoder = Ppmd.Ppmd7Encoder(self._buf, level, mem) # type: ignore def compress(self, data: Union[bytes, bytearray, memoryview]) -> bytes: self.encoder.encode(data) return self._buf.read() def flush(self): self.encoder.flush() return self._buf.read()
class ZstdDecompressor(ISevenZipDecompressor): def __init__(self, properties): if Zstd is None or len(properties) not in [3, 5] or (properties[0], properties[1], 0) > Zstd.ZSTD_VERSION: raise UnsupportedCompressionMethodError self._buf = BufferedRW() ctx = Zstd.ZstdDecompressor() # type: ignore self._decompressor = ctx.stream_writer(self._buf) def decompress(self, data: Union[bytes, bytearray, memoryview], max_length: int = -1) -> bytes: self._decompressor.write(data) if max_length > 0: result = self._buf.read(max_length) else: result = self._buf.read() return result
class ZstdCompressor(): def __init__(self, level): self._buf = BufferedRW() ctx = zstandard.ZstdCompressor(level) # type: ignore self._compressor = ctx.stream_writer(self._buf) self.flushed = False def compress(self, data: Union[bytes, bytearray, memoryview]) -> bytes: self._compressor.write(data) result = self._buf.read() return result def flush(self): if self.flushed: return None self._compressor.flush(zstandard.FLUSH_FRAME) self.flushed = True result = self._buf.read() return result
class ZstdCompressor(ISevenZipCompressor): def __init__(self): if Zstd is None: raise UnsupportedCompressionMethodError self._buf = BufferedRW() ctx = Zstd.ZstdCompressor() # type: ignore self._compressor = ctx.stream_writer(self._buf) self.flushed = False def compress(self, data: Union[bytes, bytearray, memoryview]) -> bytes: self._compressor.write(data) result = self._buf.read() return result def flush(self): if self.flushed: return None self._compressor.flush(Zstd.FLUSH_FRAME) self.flushed = True result = self._buf.read() return result