Unzip zip resources file

Unzip zip resources file

Amremad
Collaborator Collaborator
469 Views
1 Reply
Message 1 of 2

Unzip zip resources file

Amremad
Collaborator
Collaborator

hello all 

i have an resources file called file.zip

to unzip it i must copy it to hard disk  and i have no problem to copy outside it and unzip it directly using ZipFile class

 

but my question how can i zip it without copy it , i mean using memory stream 

i begin from this line but i can't to complete my code to send the stream to ZipFile 

            string resource = "Installer.Resources.myFile.zip";
            System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
            Stream resFilestream = a.GetManifestResourceStream(resource);
            //ZipArchive archive = ZipFile.OpenRead(resFilestream);

OpenRead must give it an string path to can read the archive , but i need to use the stream variable to can unzip some contains not all in this archive. 

 

i hope my question is clear šŸ™‚ 

0 Likes
470 Views
1 Reply
Reply (1)
Message 2 of 2

moogalm
Autodesk Support
Autodesk Support

If I understand correctly, you are looking for reading entries in-memory of an archive.

For example, I have .zip file which wraps a *.txt file.

 

 static void Main(string[] args)
        {
            using (FileStream zipToOpen = new FileStream(@"D:\dotnetsnips\inmemroryArchive\reader.zip", FileMode.Open))
            {
                using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read))
                {
                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
                        {
                            using (StreamReader reader = new StreamReader(entry.Open()))
                            {
                                Console.WriteLine(reader.ReadLine());
                            }
                        }

                    }
                }
            }
        }
0 Likes