lz4/lz4-java

Wrong data after extraction with 7z-zstd

DanielRuf opened this issue · 4 comments

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?

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();

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?

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

Added an example with d6759a6.