1*27162e4eSAndroid Build Coastguard WorkerCommand Line Interface for LZ4 library 2*27162e4eSAndroid Build Coastguard Worker============================================ 3*27162e4eSAndroid Build Coastguard Worker 4*27162e4eSAndroid Build Coastguard Worker### Build 5*27162e4eSAndroid Build Coastguard WorkerThe `lz4` Command Line Interface (CLI) is generated 6*27162e4eSAndroid Build Coastguard Workerusing the `make` command, no additional parameter required. 7*27162e4eSAndroid Build Coastguard Worker 8*27162e4eSAndroid Build Coastguard WorkerThe CLI generates and decodes [LZ4-compressed frames](../doc/lz4_Frame_format.md). 9*27162e4eSAndroid Build Coastguard Worker 10*27162e4eSAndroid Build Coastguard WorkerFor more control over the build process, 11*27162e4eSAndroid Build Coastguard Workerthe `Makefile` script supports all [standard conventions](https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html), 12*27162e4eSAndroid Build Coastguard Workerincluding standard targets (`all`, `install`, `clean`, etc.) 13*27162e4eSAndroid Build Coastguard Workerand standard variables (`CC`, `CFLAGS`, `CPPFLAGS`, etc.). 14*27162e4eSAndroid Build Coastguard Worker 15*27162e4eSAndroid Build Coastguard WorkerThe makefile offer several targets for various use cases: 16*27162e4eSAndroid Build Coastguard Worker- `lz4` : default CLI, with a command line syntax similar to gzip 17*27162e4eSAndroid Build Coastguard Worker- `lz4c` : supports legacy lz4 commands (incompatible with gzip) 18*27162e4eSAndroid Build Coastguard Worker- `lz4c32` : Same as `lz4c`, but generates a 32-bits executable 19*27162e4eSAndroid Build Coastguard Worker- `unlz4`, `lz4cat` : symlinks to `lz4`, default to decompression and `cat` compressed files 20*27162e4eSAndroid Build Coastguard Worker- `man` : generates the man page, from `lz4.1.md` markdown source 21*27162e4eSAndroid Build Coastguard Worker 22*27162e4eSAndroid Build Coastguard Worker#### Makefile Build variables 23*27162e4eSAndroid Build Coastguard Worker- `HAVE_MULTITHREAD` : build with multithreading support. Detection is generally automatic, but can be forced to `0` or `1` if needed. This is for example useful when cross-compiling for Windows from Linux. 24*27162e4eSAndroid Build Coastguard Worker- `HAVE_PTHREAD` : determines presence of `<pthread>` support. Detection is automatic, but can be forced to `0` or `1` if needed. This is in turn used by `make` to automatically trigger multithreading support. 25*27162e4eSAndroid Build Coastguard Worker 26*27162e4eSAndroid Build Coastguard Worker#### C Preprocessor Build variables 27*27162e4eSAndroid Build Coastguard WorkerThese variables are read by the preprocessor at compilation time. They influence executable behavior, such as default starting values, and are exposed from `programs/lz4conf.h`. These variables can manipulated by any build system. 28*27162e4eSAndroid Build Coastguard WorkerAssignment methods vary depending on environments. 29*27162e4eSAndroid Build Coastguard WorkerOn a typical `posix` + `gcc` + `make` setup, they can be defined with `CPPFLAGS=-DVARIABLE=value` assignment. 30*27162e4eSAndroid Build Coastguard Worker- `LZ4_CLEVEL_DEFAULT`: default compression level when none provided. Default is `1`. 31*27162e4eSAndroid Build Coastguard Worker- `LZ4IO_MULTITHREAD`: enable multithreading support. Default is disabled. 32*27162e4eSAndroid Build Coastguard Worker- `LZ4_NBWORKERS_DEFAULT`: default nb of worker threads used in multithreading mode (can be overridden with command `-T#`). 33*27162e4eSAndroid Build Coastguard Worker Default is `0`, which means "auto-determine" based on local cpu. 34*27162e4eSAndroid Build Coastguard Worker- `LZ4_NBWORKERS_MAX`: absolute maximum nb of workers that can be requested at runtime. 35*27162e4eSAndroid Build Coastguard Worker Currently set to 200 by default. 36*27162e4eSAndroid Build Coastguard Worker This is mostly meant to protect the system against unreasonable and likely bogus requests, such as a million threads. 37*27162e4eSAndroid Build Coastguard Worker- `LZ4_BLOCKSIZEID_DEFAULT`: default `lz4` block size code. Valid values are [4-7], corresponding to 64 KB, 256 KB, 1 MB and 4 MB. At the time of this writing, default is 7, corresponding to 4 MB block size. 38*27162e4eSAndroid Build Coastguard Worker 39*27162e4eSAndroid Build Coastguard Worker#### Environment Variables 40*27162e4eSAndroid Build Coastguard WorkerIt's possible to pass some parameters to `lz4` via environment variables. 41*27162e4eSAndroid Build Coastguard WorkerThis can be useful in situations where `lz4` is known to be invoked (from within a script for example) but there is no way to pass `lz4` parameters to influence the compression session. 42*27162e4eSAndroid Build Coastguard WorkerThe environment variable has higher priority than binary default, but lower priority than corresponding runtime command. 43*27162e4eSAndroid Build Coastguard WorkerWhen set as global environment variables, it can enforce personalized defaults different from the binary set ones. 44*27162e4eSAndroid Build Coastguard Worker 45*27162e4eSAndroid Build Coastguard Worker`LZ4_CLEVEL` can be used to specify a default compression level that `lz4` employs for compression when no other compression level is specified on command line. Executable default is generally `1`. 46*27162e4eSAndroid Build Coastguard Worker 47*27162e4eSAndroid Build Coastguard Worker`LZ4_NBWORKERS` can be used to specify a default number of threads that `lz4` will employ for compression. Executable default is generally `0`, which means auto-determined based on local cpu. This functionality is only relevant when `lz4` is compiled with multithreading support. The maximum number of workers is capped at `LZ4_NBWORKERS_MAX` (`200` by default). 48*27162e4eSAndroid Build Coastguard Worker 49*27162e4eSAndroid Build Coastguard Worker### Aggregation of parameters 50*27162e4eSAndroid Build Coastguard WorkerThe `lz4` CLI supports aggregation for short commands. For example, `-d`, `-q`, and `-f` can be joined into `-dqf`. 51*27162e4eSAndroid Build Coastguard WorkerAggregation doesn't work for `--long-commands`, which **must** be separated. 52*27162e4eSAndroid Build Coastguard Worker 53*27162e4eSAndroid Build Coastguard Worker 54*27162e4eSAndroid Build Coastguard Worker### Benchmark in Command Line Interface 55*27162e4eSAndroid Build Coastguard Worker`lz4` CLI includes an in-memory compression benchmark module, triggered by command `-b#`, with `#` representing the compression level. 56*27162e4eSAndroid Build Coastguard WorkerThe benchmark is conducted on a provided list of filenames. 57*27162e4eSAndroid Build Coastguard WorkerThe files are then read entirely into memory, to eliminate I/O overhead. 58*27162e4eSAndroid Build Coastguard WorkerWhen multiple files are provided, they are bundled into the same benchmark session (though each file is a separate compression / decompression). Using `-S` command separates them (one session per file). 59*27162e4eSAndroid Build Coastguard WorkerWhen no file is provided, uses an internal Lorem Ipsum generator instead. 60*27162e4eSAndroid Build Coastguard Worker 61*27162e4eSAndroid Build Coastguard WorkerThe benchmark measures ratio, compressed size, compression and decompression speed. 62*27162e4eSAndroid Build Coastguard WorkerOne can select multiple compression levels starting from `-b` and ending with `-e` (ascending). 63*27162e4eSAndroid Build Coastguard WorkerThe `-i` parameter selects a number of seconds used for each session. 64*27162e4eSAndroid Build Coastguard Worker 65*27162e4eSAndroid Build Coastguard Worker 66*27162e4eSAndroid Build Coastguard Worker### Usage of Command Line Interface 67*27162e4eSAndroid Build Coastguard WorkerThe full list of commands can be obtained with `-h` or `-H` parameter: 68*27162e4eSAndroid Build Coastguard Worker``` 69*27162e4eSAndroid Build Coastguard WorkerUsage : 70*27162e4eSAndroid Build Coastguard Worker lz4 [arg] [input] [output] 71*27162e4eSAndroid Build Coastguard Worker 72*27162e4eSAndroid Build Coastguard Workerinput : a filename 73*27162e4eSAndroid Build Coastguard Worker with no FILE, or when FILE is - or stdin, read standard input 74*27162e4eSAndroid Build Coastguard WorkerArguments : 75*27162e4eSAndroid Build Coastguard Worker -1 : Fast compression (default) 76*27162e4eSAndroid Build Coastguard Worker -9 : High compression 77*27162e4eSAndroid Build Coastguard Worker -d : decompression (default for .lz4 extension) 78*27162e4eSAndroid Build Coastguard Worker -z : force compression 79*27162e4eSAndroid Build Coastguard Worker -D FILE: use FILE as dictionary 80*27162e4eSAndroid Build Coastguard Worker -f : overwrite output without prompting 81*27162e4eSAndroid Build Coastguard Worker -k : preserve source files(s) (default) 82*27162e4eSAndroid Build Coastguard Worker--rm : remove source file(s) after successful de/compression 83*27162e4eSAndroid Build Coastguard Worker -h/-H : display help/long help and exit 84*27162e4eSAndroid Build Coastguard Worker 85*27162e4eSAndroid Build Coastguard WorkerAdvanced arguments : 86*27162e4eSAndroid Build Coastguard Worker -V : display Version number and exit 87*27162e4eSAndroid Build Coastguard Worker -v : verbose mode 88*27162e4eSAndroid Build Coastguard Worker -q : suppress warnings; specify twice to suppress errors too 89*27162e4eSAndroid Build Coastguard Worker -c : force write to standard output, even if it is the console 90*27162e4eSAndroid Build Coastguard Worker -t : test compressed file integrity 91*27162e4eSAndroid Build Coastguard Worker -m : multiple input files (implies automatic output filenames) 92*27162e4eSAndroid Build Coastguard Worker -r : operate recursively on directories (sets also -m) 93*27162e4eSAndroid Build Coastguard Worker -l : compress using Legacy format (Linux kernel compression) 94*27162e4eSAndroid Build Coastguard Worker -B# : cut file into blocks of size # bytes [32+] 95*27162e4eSAndroid Build Coastguard Worker or predefined block size [4-7] (default: 7) 96*27162e4eSAndroid Build Coastguard Worker -BD : Block dependency (improve compression ratio) 97*27162e4eSAndroid Build Coastguard Worker -BX : enable block checksum (default:disabled) 98*27162e4eSAndroid Build Coastguard Worker--no-frame-crc : disable stream checksum (default:enabled) 99*27162e4eSAndroid Build Coastguard Worker--content-size : compressed frame includes original size (default:not present) 100*27162e4eSAndroid Build Coastguard Worker--[no-]sparse : sparse mode (default:enabled on file, disabled on stdout) 101*27162e4eSAndroid Build Coastguard Worker--favor-decSpeed: compressed files decompress faster, but are less compressed 102*27162e4eSAndroid Build Coastguard Worker--fast[=#]: switch to ultra fast compression level (default: 1) 103*27162e4eSAndroid Build Coastguard Worker 104*27162e4eSAndroid Build Coastguard WorkerBenchmark arguments : 105*27162e4eSAndroid Build Coastguard Worker -b# : benchmark file(s), using # compression level (default : 1) 106*27162e4eSAndroid Build Coastguard Worker -e# : test all compression levels from -bX to # (default : 1) 107*27162e4eSAndroid Build Coastguard Worker -i# : minimum evaluation time in seconds (default : 3s)``` 108*27162e4eSAndroid Build Coastguard Worker``` 109*27162e4eSAndroid Build Coastguard Worker 110*27162e4eSAndroid Build Coastguard Worker#### License 111*27162e4eSAndroid Build Coastguard Worker 112*27162e4eSAndroid Build Coastguard WorkerAll files in this directory are licensed under GPL-v2. 113*27162e4eSAndroid Build Coastguard WorkerSee [COPYING](COPYING) for details. 114*27162e4eSAndroid Build Coastguard WorkerThe text of the license is also included at the top of each source file. 115