Elixir 压缩模块
2023-12-17 18:56 更新
zip
模块让你能够在硬盘和内存中读写zip文件,也可以提取文件信息.
下列代码计算了一个zip文件中的文件数量:
iex> :zip.foldl(fn _, _, _, acc -> acc + 1 end, 0, :binary.bin_to_list("file.zip"))
{:ok, 633}
zlib
模块用于以zlib格式压缩文件,类似gzip
命令.
iex> song = "
...> Mary had a little lamb,
...> His fleece was white as snow,
...> And everywhere that Mary went,
...> The lamb was sure to go."
iex> compressed = :zlib.compress(song)
iex> byte_size song
110
iex> byte_size compressed
99
iex> :zlib.uncompress(compressed)
"\nMary had a little lamb,\nHis fleece was white as snow,\nAnd everywhere that Mary went,\nThe lamb was sure to go."
以上内容是否对您有帮助:
更多建议: