C# 使用Lz4net对字节数组进行编码和解码
这是使用C# 使用Lz4net对字节数组进行编码和解码,c#,lz4,C#,Lz4,这是使用Lz4net对字节数组进行编码和解码的正确方法吗 byte[] filedata = File.ReadAllBytes(@"C:\Test.txt"); byte[] encodedfileData = LZ4.LZ4Codec.Encode(filedata, 0, filedata.Length); byte[] decodedfileData = LZ4.LZ4Codec.Decode(encodedfileData, 0, encodedfileData.Length, 0);
Lz4net
对字节数组进行编码和解码的正确方法吗
byte[] filedata = File.ReadAllBytes(@"C:\Test.txt");
byte[] encodedfileData = LZ4.LZ4Codec.Encode(filedata, 0, filedata.Length);
byte[] decodedfileData = LZ4.LZ4Codec.Decode(encodedfileData, 0, encodedfileData.Length, 0);
decodedfileData
返回0字节
我经历过,但我不知道出了什么问题。那么,使用LZ4
对字节数组进行编码和解码的正确方法是什么?您可以尝试以下方法:
byte[] filedata = File.ReadAllBytes(@"C:\Test.txt");
byte[] compressed = LZ4.LZ4Codec.Wrap(in);
byte[] uncompressed = LZ4.LZ4Codec.UnWrap(compressed);
您需要将未打包的大小(filedata.Length
)作为最后一个参数:
byte[] decodedfileData = LZ4.LZ4Codec.Decode(
encodedfileData,
0,
encodedfileData.Length,
filedata.Length);
你只想压缩它吗?为什么不使用“wrap”?@farbiondriven我正在使用更大字节数组的图像传输程序。我不知道wrap与大字节数组字节兼容