Compression using LZ4Net

荒凉一梦 提交于 2019-12-11 05:32:56

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/37627462/compression-using-lz4net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!