user5856827
user5856827

Reputation:

Compression using LZ4Net

I'm trying to compress multiple files with lz4net, but I don't even know how to begin.

I have string[] or List<string> with filepaths (and relative paths) and want to compress it with lz4 to one file.

Later I want to decompress it with taking care about the relative paths.

Upvotes: 1

Views: 7724

Answers (1)

Shai Segev
Shai Segev

Reputation: 121

Download the LZ4 dll.

Create a buffer for each file:

public byte[] FileToByteArray(string fileName)
{
    byte[] buff = null;
    FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
    BinaryReader br = new BinaryReader(fs);
    long numBytes = new FileInfo(fileName).Length;
    buff = br.ReadBytes((int)numBytes);
    return buff;
}

Then, use the buffers to commpress/decompress like this:

LZ4.LZ4Codec.Decode(input, offset, inputLength, outputLength); // Decoder
LZ4.LZ4Codec.Encode(input, offset, inputLength); // Encoder

If you are looking, here is the full version of the LZ4 dll (includes frames compression).

Upvotes: 1

Related Questions