如何在 Erlang 中使用 zlib 压缩列表并将其解压回来?
假设我想压缩以下列表并将压缩版本保留在 RAM 中:
List = lists:seq(1,100000).
官方 文档 对我不起作用 - 我收到未绑定变量 Read
的错误,并且我不明白它的用途(是函数还是变量?) 。
我尝试在网络上搜索,但我发现的唯一内容与解压缩有关
所以,问题是:如何在 Erlang 中使用 zlib
压缩列表 List
并将其解压回来?如何查看 List
及其压缩对应项消耗了多少内存?
Let's say I would like to compress the following list and keep the compressed version in RAM:
List = lists:seq(1,100000).
The example provided in the official documentation doesn't work for me - I get the error for unbound variable Read
and I do not understand what it is used for (is it a function or a variable?).
I have tried to search on the web, but the only thing that I have found is related to decompressing files.
So, the question is: How can I compress the list List
and decompress it back with the help of zlib
in Erlang? How can I see what amount of memory is consumed by the List
and its compressed counterpart?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
term_to_binary/2 BIF 支持 zlib 压缩:
binary_to_term/1 将识别zlib 标头并做正确的事情。
The term_to_binary/2 BIF supports zlib compression:
binary_to_term/1 will recognize the zlib header and do the right thing.
您可以通过以下方式压缩数据:
要解压缩数据,您可以执行以下操作:
您可以通过检查 CData 来计算出大小。
You can compress the data in the following manner:
To decompress the data you can do:
You can just figure out the size by checking CData.