Sharpziplib 解压缩嵌入资源

发布于 2024-10-06 09:42:57 字数 963 浏览 8 评论 0原文

我有一个 zip 文件作为嵌入资源。使用以下代码:

Stream zipStream;
zipStream = thisAssembly.GetManifestResourceStream("Namespace.Resources.zipfile.zip");
byte[] data = Decompress(zipStream);

    public static byte[] Decompress(Stream zipStream)
            {
                ZipInputStream zipInputStream = new ZipInputStream(zipStream);
                //zipInputStream.CanDecompressEntry is false
                ZipEntry zipEntry;
                MemoryStream zipoutStream = new MemoryStream();

                while((zipEntry = zipInputStream.GetNextEntry()) != null)
                {
                    byte[] buffer = new byte[zipInputStream.Length];
                    zipInputStream.Read(buffer, 0, (int)zipInputStream.Length);
                    zipoutStream.Read(buffer, 0, buffer.Length);
                }
                return zipoutStream.ToArray();
            }

解压缩方法始终返回 null。 CanDecompressEntry 始终为 false。还有其他方法来解压嵌入资源吗?

I have a zip file as an embedded resource. Using the following code:

Stream zipStream;
zipStream = thisAssembly.GetManifestResourceStream("Namespace.Resources.zipfile.zip");
byte[] data = Decompress(zipStream);

    public static byte[] Decompress(Stream zipStream)
            {
                ZipInputStream zipInputStream = new ZipInputStream(zipStream);
                //zipInputStream.CanDecompressEntry is false
                ZipEntry zipEntry;
                MemoryStream zipoutStream = new MemoryStream();

                while((zipEntry = zipInputStream.GetNextEntry()) != null)
                {
                    byte[] buffer = new byte[zipInputStream.Length];
                    zipInputStream.Read(buffer, 0, (int)zipInputStream.Length);
                    zipoutStream.Read(buffer, 0, buffer.Length);
                }
                return zipoutStream.ToArray();
            }

The decompress method always returns null. CanDecompressEntry is always false. Any other way to unzip embedded resources?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌面超妹 2024-10-13 09:42:57

也许问题出在“zipoutStream.Read”而不是“zipoutStream.Write”?

Maybe the problem is in "zipoutStream.Read" instead of "zipoutStream.Write"?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文