首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我在7-ZipSDK上收到数据错误异常?winrar 5解压缩

为什么我在7-ZipSDK上收到数据错误异常?winrar 5解压缩
EN

Stack Overflow用户
提问于 2021-03-26 15:03:27
回答 1查看 292关注 0票数 0

我附加了特殊的winrar存档,sdk给了我错误。拜托你能帮帮我吗?

用于模拟错误和测试的存档

打电话给示例:

代码语言:javascript
复制
 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;
    }

当调用代码函数时出现异常:

代码语言:javascript
复制
decoder.Code(inStream, outStream, inStream.Length - inStream.Position, outSize, null);

https://www.7-zip.org/sdk.html ver.19.00

异常调试详细信息

想要的行为: 7zip支持winrar,那么我的代码出了什么问题?

存档格式信息:https://superuser.com/questions/770370/what-is-the-difference-between-rar-and-rar5-compression

EN

回答 1

Stack Overflow用户

发布于 2021-03-28 12:26:10

无法使用LZMA SDK提取RAR档案:

  • RAR不使用LZMA作为压缩算法,LZMA SDK也不支持RAR。
  • Zip和LZMA SDK不是一回事。
  • 7-Zip使用RARLAB的unrar代码,这是专有的。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66819420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档