没有足够的zstd压缩示例。我使用的是zstandard 0.8.1,试图一次压缩2字节。在使用write_to(fh)时遇到了https://anaconda.org/rolando/zstandard,但不确定如何使用它。下面是我的部分代码,试图从文件中读取chuck字节,然后将每个chuck,cctx = zstd.ZstdCompressor(level=4) with open(path,'rb')压缩为fh: while True: bin_data = fh.read(2) #read 2 bytes if not bin_data: break压缩= cctx.compress(bin_data) fh.close()
with open(path, 'rb') as fh:
with open(outpath, 'wb') as outfile:
outfile.write(compressed)
...但是我该如何使用write_to()呢?
发布于 2018-01-12 18:05:41
我想我找到了正确的方法来使用zstd 0.8.1模块来流式传输字节块:
with open(filename, 'wb') as fh:
cctx = zstd.ZstdCompressor(level=4)
with cctx.write_to(fh) as compressor:
compressor.write(b'data1')
compressor.write(b'data2')
with open(filename, 'rb') as fh:
cctx = zstd.ZstdCompressor(level=4)
for chunk in cctx.read_from(fh, read_size=128, write_size=128):
#do somethinghttps://stackoverflow.com/questions/48202879
复制相似问题