lz4 / lz4-java

LZ4 compression for Java
Apache License 2.0
1.1k stars 253 forks source link

Wrong data after extraction with 7z-zstd #139

Closed DanielRuf closed 5 years ago

DanielRuf commented 5 years ago
LZ4Factory factory = LZ4Factory.fastestInstance();

    byte[] data = "12345345234572".getBytes("UTF-8");
    final int decompressedLength = data.length;

    LZ4Compressor compressor = factory.fastCompressor();
    int maxCompressedLength = compressor.maxCompressedLength(decompressedLength);
    byte[] compressed = new byte[maxCompressedLength];
    int compressedLength = compressor.compress(data, 0, decompressedLength, compressed, 0, maxCompressedLength);

    FileOutputStream outputStream = new FileOutputStream(new File("test.lz4"));
    LZ4FrameOutputStream stream = new LZ4FrameOutputStream(outputStream);
    stream.write(compressed);
    stream.flush();
    //stream.finish();

After this I use 7z-zstd and get a file with the content à123..., VS Code shows �12345345234572 and a few other invisible characters at the end.

What is the correct and recommended way to compress data (file / files) to a single lz4 archive / file?

odaira commented 5 years ago

LZ4FrameOutputStream accepts original uncompressed data, not compressed data.

    LZ4Factory factory = LZ4Factory.fastestInstance();

    byte[] data = "12345345234572".getBytes("UTF-8");

        FileOutputStream outputStream = new FileOutputStream(new File("test.lz4"));
    LZ4FrameOutputStream stream = new LZ4FrameOutputStream(outputStream);
    stream.write(data);
    stream.close();
DanielRuf commented 5 years ago

Oh ok. Checked the Block example in a few issues but it adds LZ4Block to generated files.

The docs seem a bit unclear for me to easily generate a LZ4 file / archive from another file.

Or did I oversee something?

odaira commented 5 years ago

Thanks for the feedback. I agree that the documentation is too lean. I'll add some examples.

odaira commented 5 years ago

Added an example with d6759a6bab9cd869bdd25ca8ea20228dc7594d3b.