没有足够的 zstd 压缩示例。我正在使用 zstandard 0.8.1,尝试一次压缩 2 个字节。在使用时遇到了https://anaconda.org/rolando/zstandardwrite_to(fh)
,但不知道如何使用它。下面是我尝试从文件中读取一个chuck字节的部分代码,然后压缩每个chuck,cctx = zstd.ZstdCompressor(level=4) with open(path, 'rb') as fh: while True: bin_data = fh.read (2) #read 2 bytes if not bin_data: break compressed = cctx.compress(bin_data) fh.close()
with open(path, 'rb') as fh:
with open(outpath, 'wb') as outfile:
outfile.write(compressed)
...
但是我应该如何使用 write_to()?