|
This version is still in development and is not considered stable yet. For the latest stable version, please use Compress4J 5.x! |
LZ4
LZ4 needs no extra dependency. It has two formats, so it has two Compression factories: Compression.lz4Framed() for the .lz4 files the lz4 command line tool writes, and Compression.lz4Block() for the raw block format.
Decompressor detects the framed format, never the block format. Block data passes through Decompressor.builder(p) unchanged: use Decompressor.builder(p, Compression.lz4Block()). The framed codec has one option, decompressConcatenated, to read concatenated frames.
Decompressor enforces the default limits; a stream that expands past a ratio of 100 after the first MiB throws LimitExceededException.
Example Usage
try (Compressor compressor = Compressor.builder(Path.of("example.lz4"), Compression.lz4Framed())
.build()) {
compressor.write(Path.of("path/to/file.txt"));
}
Compression lz4 = Compression.lz4Framed().decompressConcatenated(true);
try (Decompressor decompressor =
Decompressor.builder(Path.of("example.lz4"), lz4).build()) {
decompressor.write(Path.of("path/to/file.txt"));
}
try (Compressor compressor = Compressor.builder(Path.of("example.block_lz4"), Compression.lz4Block())
.build()) {
compressor.write(Path.of("path/to/file.txt"));
}
try (Decompressor decompressor = Decompressor.builder(Path.of("example.block_lz4"), Compression.lz4Block())
.build()) {
decompressor.write(Path.of("path/to/file.txt"));
}
The .tar.lz4 format uses the framed codec; see tar.