def __decompress_zst_file(self, file, with_extension): with open(file, 'rb') as compressed: decomp = ZstdDecompressor() filename = os.path.splitext(file)[0] file_name = f"{self.destination_folder}/{file.name}{with_extension}" with open(file_name, 'wb') as destination: decomp.copy_stream(compressed, destination) print_green(f"unpacked zst file completed to {file_name}")
def decompress(self, fobj: IO[bytes]) -> IO[bytes]: decompressor = ZstdDecompressor() outfobj = NamedTemporaryFile(delete=False) try: decompressor.copy_stream(fobj, outfobj) outfobj.seek(0) yield outfobj finally: outfobj.close() remove(outfobj.name)
def open_read(self, path: str) -> IO[bytes]: decompressor = ZstdDecompressor() outfobj = NamedTemporaryFile(delete=False) try: with open(path, 'rb') as infobj: decompressor.copy_stream(infobj, outfobj) outfobj.seek(0) yield outfobj finally: outfobj.close() remove(outfobj.name)