This project is read-only.

Example use of LZ4Stream

May 21, 2014 at 10: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)\lz4net-\source\LZ4\LZ4Stream.cs:line 241

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

at LZ4.Program.Main(String[] args) in c:\Users\xxx\Downloads\lz4net- (1)\lz4net-\source\LZ4Test\Program.cs:line 19
I am wondering if there is any example code to use LZ4Stream. Thanks!
May 23, 2014 at 10: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 :
  2. File and streaming compression use a container format :
While lz4net is compatible with 1, it is not compatible with 2.