You are viewing the documentation for a prerelease version. View Latest

LZ4

LZ4 support needs no extra dependency. Compress4J provides two stream types, because they are different formats: the framed format (the .lz4 files written by the lz4 command line tool) and the raw block format.

The framed decompressor can read concatenated frames when setDecompressConcatenated(true) is set.

Closing a block LZ4 compressor without writing any data fails inside Commons Compress with an IndexOutOfBoundsException. Write at least one byte before closing it.

Example Usage

Framed LZ4 Compression
try (Lz4FramedCompressor lz4Compressor =
        Lz4FramedCompressor.builder(Path.of("example.lz4")).build()) {
    lz4Compressor.write(Path.of("path/to/file.txt"));
}
Framed LZ4 Decompression
try (Lz4FramedDecompressor lz4Decompressor = Lz4FramedDecompressor.builder(Path.of("example.lz4"))
        .compressorInputStreamBuilder()
        .setDecompressConcatenated(true)
        .parentBuilder()
        .build()) {
    lz4Decompressor.write(Path.of("path/to/file.txt"));
}
Block LZ4 Compression
try (Lz4BlockCompressor lz4Compressor =
        Lz4BlockCompressor.builder(Path.of("example.block_lz4")).build()) {
    lz4Compressor.write(Path.of("path/to/file.txt"));
}
Block LZ4 Decompression
try (Lz4BlockDecompressor lz4Decompressor =
        Lz4BlockDecompressor.builder(Path.of("example.block_lz4")).build()) {
    lz4Decompressor.write(Path.of("path/to/file.txt"));
}

The .tar.lz4 creator and extractor use the framed format; see tar.