使用LZ4Net压缩 [英] Compression using LZ4Net
本文介绍了使用LZ4Net压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用lz4net压缩多个文件,但我什至不知道如何开始。
I'm trying to compress multiple files with lz4net, but I don't even know how to begin.
我有 string [ ]
或 List< string>
包含文件路径(以及相对路径),并希望将其与lz4压缩为一个文件。
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.
推荐答案
下载 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
如果您正在寻找,请这是LZ4 dll的完整版本(包括帧压缩)。
If you are looking, here is the full version of the LZ4 dll (includes frames compression).
这篇关于使用LZ4Net压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文