Example use of LZ4Stream

May 21, 2014 at 9:33 PM
I am using LZ4(r117) CLI (lz4 -9 [input] [output]) to compress the data and using LZ4Stream to decompress the data with the following code.
         string lz4File = @"test.lz4";
         byte[] buffer = new byte[1024];
         using(var fs = new FileStream(lz4File, FileMode.Open, FileAccess.Read, FileShare.Read, 1024*1024))
         using (var lzStream = new LZ4Stream(fs, CompressionMode.Decompress))
         {
            int bytesRead = lzStream.Read(buffer, 0, buffer.Length);
         }
The code throws an exception with "Chunk with multiple passes are not supported".
at LZ4.LZ4Stream.AcquireNextChunk() in c:\Users\xxx\Downloads\lz4net-1.0.3.93-src (1)\lz4net-1.0.3.93\source\LZ4\LZ4Stream.cs:line 241

at LZ4.LZ4Stream.Read(Byte[] buffer, Int32 offset, Int32 count) in c:\Users\xxx\Downloads\lz4net-1.0.3.93-src (1)\lz4net-1.0.3.93\source\LZ4\LZ4Stream.cs:line 333

at LZ4.Program.Main(String[] args) in c:\Users\xxx\Downloads\lz4net-1.0.3.93-src (1)\lz4net-1.0.3.93\source\LZ4Test\Program.cs:line 19
I am wondering if there is any example code to use LZ4Stream. Thanks!
Coordinator
May 23, 2014 at 9:26 AM
Quick answer is: no.
As LZ4 is block compression algorithm C and C# implementation use different method to put them (those blocks) into stream. Single blocks from lz4 and lz4net are compatible but the streams aren't.

On LZ4 webpage you will find:
  1. The LZ4 block compression format is detailed here : http://fastcompression.blogspot.com/2011/05/lz4-explained.html
  2. File and streaming compression use a container format : http://fastcompression.blogspot.fr/2013/04/lz4-streaming-format-final.html
While lz4net is compatible with 1, it is not compatible with 2.