Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top