A G
A G

Reputation: 22577

Sharpziplib uncompress embedded resource

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?

Upvotes: 1

Views: 3199

Answers (1)

Alex Shtoff
Alex Shtoff

Reputation: 2640

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

Upvotes: 1

Related Questions