【发布时间】:2021-03-26 15:03:27
【问题描述】:
我附加了特殊的 winrar 存档,其中 sdk 给了我错误。拜托,你能帮帮我吗?
archive for simulate bug and test
调用示例:
MemoryStream inputMemoryStream = new MemoryStream();
string archiveFilePath = @"c:\winrar.rar";
File.OpenRead(archiveFilePath).CopyTo(inputMemoryStream);
var bb = ExtractBytes(inputMemoryStream.ToArray());
private byte[] ExtractBytes(byte[] data)
{
using (var inStream = new MemoryStream(data))
{
var decoder = new SevenZip.Compression.LZMA.Decoder();
inStream.Seek(0, 0);
using (var outStream = new MemoryStream())
{
long outSize;
decoder.SetDecoderProperties(GetLzmaProperties(inStream, out outSize));
decoder.Code(inStream, outStream, inStream.Length - inStream.Position, outSize, null);
return outStream.ToArray();
}
}
}
private byte[] GetLzmaProperties(Stream inStream, out long outSize)
{
var lzmAproperties = new byte[5];
if (inStream.Read(lzmAproperties, 0, 5) != 5)
{
throw new Exception("LzmaException");
}
outSize = 0;
for (int i = 0; i < 8; i++)
{
int b = inStream.ReadByte();
if (b < 0)
{
throw new Exception("LzmaException");
}
outSize |= ((long)(byte)b) << (i << 3);
}
return lzmAproperties;
}
调用代码函数时发生异常:
decoder.Code(inStream, outStream, inStream.Length - inStream.Position, outSize, null);
https://www.7-zip.org/sdk.html 19.00版
期望的行为:7zip 支持 winrar,那么我的代码出了什么问题?
存档格式信息:https://superuser.com/questions/770370/what-is-the-difference-between-rar-and-rar5-compression
【问题讨论】: