Sharpziplib解压缩嵌入式资源

时间:2010-12-06 12:35:58

标签: c# unzip sharpziplib

我有一个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。解压缩嵌入资源的其他任何方式?

1 个答案:

答案 0 :(得分:1)

问题可能在于“zipoutStream.Read”而不是“zipoutStream.Write”?