lz4 快速压缩工具

发布时间: 更新时间: 总字数:611 阅读时间:2m 作者: IP上海 分享 网址

lz4 利用 CPU 多核,压缩/解压速度很快,压缩率比较低,lz4 解压缩的对象是文件而非目录

介绍

  • 优点
    • 压缩/解压速度非常快,大约是 gzip 的 10 倍

安装

  • centos
yum install -y lz4 lz4-devel
  • ubuntu
apt install -y lz4

help

lz4 --help ...
$ lz4 --help
*** LZ4 command line interface 64-bits v1.9.2, by Yann Collet ***
Usage :
      lz4 [arg] [input] [output]

input   : a filename
          with no FILE, or when FILE is - or stdin, read standard input
Arguments :
 -1     : Fast compression (default)
 -9     : High compression
 -d     : decompression (default for .lz4 extension)
 -z     : force compression
 -D FILE: use FILE as dictionary
 -f     : overwrite output without prompting
 -k     : preserve source files(s)  (default)
--rm    : remove source file(s) after successful de/compression
 -h/-H  : display help/long help and exit

Advanced arguments :
 -V     : display Version number and exit
 -v     : verbose mode
 -q     : suppress warnings; specify twice to suppress errors too
 -c     : force write to standard output, even if it is the console
 -t     : test compressed file integrity
 -m     : multiple input files (implies automatic output filenames)
 -r     : operate recursively on directories (sets also -m)
 -l     : compress using Legacy format (Linux kernel compression)
 -B#    : cut file into blocks of size # bytes [32+]
                     or predefined block size [4-7] (default: 7)
 -BI    : Block Independence (default)
 -BD    : Block dependency (improves compression ratio)
 -BX    : enable block checksum (default:disabled)
--no-frame-crc : disable stream checksum (default:enabled)
--content-size : compressed frame includes original size (default:not present)
--list FILE : lists information about .lz4 files (useful for files compressed with --content-size flag)
--[no-]sparse  : sparse mode (default:enabled on file, disabled on stdout)
--favor-decSpeed: compressed files decompress faster, but are less compressed
--fast[=#]: switch to ultra fast compression level (default: 1)
--best  : same as -12
Benchmark arguments :
 -b#    : benchmark file(s), using # compression level (default : 1)
 -e#    : test all compression levels from -bX to # (default : 1)
 -i#    : minimum evaluation time in seconds (default : 3s)

使用

命令

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

lib 库

F&Q

error 44 unrecognized header file cannot be decoded

lz4编解码器不匹配导致

参考

  1. https://lz4.org/
  2. https://github.com/lz4/lz4
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数