首页 > 编程笔记 > 通用技能 阅读:2

LZ4下载、安装和使用教程(附安装包)

LZ4 是一款“把大文件变小、再把小文件瞬间还原”的压缩库;更准确地说,它只做一件事,就是超高速压缩与解压。

如果把 ZIP 比作稳重的中年人,讲究压缩率,那么 LZ4 就是百米飞人:牺牲一点点体积,换取几倍甚至十几倍的速度。对新手而言,你只要记住,在需要“读盘不卡、开机秒启、网络包秒传”的场合,让 LZ4 上就行了。

注意,免费开源不代表“零门槛”。LZ4 的算法本身无专利,但官方只保证“解压”格式永远稳定,压缩级别未来可能微调,因此长期归档建议同时存一份“格式版本号”;另外,它对不可压缩数据(例如已加密的随机密文)会膨胀 0.4%,存储前最好做“可压缩性探测”或预留块头标记。

下载LZ4

这里为大家提供了 LZ4 的最新版压缩包:

网盘下载:https://pan.quark.cn/s/2ef1bf36f995

网盘中有 x64 和 x32 两个版本的 Windows 版 LZ4 压缩包。

安装LZ4

对于 Windows 平台,下载网盘中的 LZ4 压缩包,解压后如下图所示:


找到 lz4.exe,它就是 LZ4,直接可以进行压缩和解压操作:
1) 压缩:将带压缩的文件用鼠标拖动到 lz4.exe 上,即可完成压缩操作:


图中展示的是将 1.png 文件拖动到 lz4.exe 上,就可以轻松得到一个名为“1.png.lz4”的压缩文件。

2) 解压:将已经压缩、格式为 .lz4 的压缩包拖动到 lz4.exe 上,即可完成解压操作:


对于 Linux 平台,安装 LZ4 也很简单:
1) centos:

yum install -y lz4 lz4-devel

2) ubuntu:

apt install -y lz4


使用 LZ4 的方式总结如下:
cp /etc/hosts hosts

# 对文件进行压缩
$ lz4 hosts
Compressed filename will be : hosts.lz4
Compressed 252 bytes into 235 bytes ==> 93.25%
$ ls
hosts  hosts.lz4
$ rm hosts.lz4

# 指定压缩率,1 快速压缩;9 高压缩。使用 -f 覆盖
$ lz4 -1 hosts
Compressed filename will be : hosts.lz4
Compressed 252 bytes into 235 bytes ==> 93.25%
$ rm hosts.lz4

$ lz4 -9 hosts
Compressed filename will be : hosts.lz4
Compressed 252 bytes into 229 bytes ==> 90.87%
$ rm hosts.lz4

# 压缩后将文件删除
$ lz4 --rm hosts
Compressed filename will be : hosts.lz4
hosts.lz4 already exists; do you wish to overwrite (y/N) ? y
Compressed 252 bytes into 235 bytes ==> 93.25%
$ ls
hosts.lz4

# 解压
$ lz4 -d hosts.lz4
Decoding file hosts
hosts.lz4            : decoded 252 bytes
$ ls
hosts  hosts.lz4

# 压缩删除源文件
$ lz4 -q -f --rm hosts
$ ls
hosts.lz4

# 多文件压缩
$ lz4 -m hosts hosts.txt
$ ls
hosts  hosts.lz4  hosts.txt  hosts.txt.lz4

相关文章