lz4 / lz4-java

LZ4 compression for Java
Apache License 2.0
1.09k stars 248 forks source link

Can't read LZ4 stream made in C# with data appended #192

Closed realkarmakun closed 2 years ago

realkarmakun commented 2 years ago

So I have a file that was compressed in C# using LZ4Stream. For some reason when I try to decompress it - I get following Exception

java.io.IOException: Stream unsupported
    at net.jpountz.lz4.LZ4FrameInputStream.nextFrameInfo(LZ4FrameInputStream.java:157)
    at net.jpountz.lz4.LZ4FrameInputStream.read(LZ4FrameInputStream.java:330)

I'm not sure what exactly am I doing wrong here. My code:

        try (var fileStream = new FileInputStream(mapDir.resolve("procedural.map").toString())) {
            if (Unpooled.wrappedBuffer(fileStream.readNBytes(4)).order(ByteOrder.LITTLE_ENDIAN).getUnsignedInt(0) == 9) {
                try (var decompressStream = new LZ4FrameInputStream(fileStream)) {
                    var data = decompressStream.read();
                }
            }
        } catch (IOException  e) {
            e.printStackTrace();
        }

I also must note that compressed data was preappended with unsigned int constant in little endian format(just number 9). Here is the file itself (it's around 50mb): Link The exact C# code that was used to create compressed file.

realkarmakun commented 2 years ago

So I figured it out. apperenlty old lz4net is not compatobile with LZ4 Frame format. What can I really do in this situation?