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

Framed LZ4 Compression
try (Compressor compressor = Compressor.builder(Path.of("example.lz4"), Compression.lz4Framed())
        .build()) {
    compressor.write(Path.of("path/to/file.txt"));
}
Framed LZ4 Decompression
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"));
}
Block LZ4 Compression
try (Compressor compressor = Compressor.builder(Path.of("example.block_lz4"), Compression.lz4Block())
        .build()) {
    compressor.write(Path.of("path/to/file.txt"));
}
Block LZ4 Decompression
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.