jaime-olivares / zipstorer

A Pure C# Class to Store Files in Zip
MIT License
183 stars 63 forks source link

not able to remove one entry #47

Open andrsbtrg opened 2 years ago

andrsbtrg commented 2 years ago

hi and thanks for the very useful utility. I am using it to manipulate .idml files which are compressed folders for adobe indesign files. Extracting a file from the directory works just fine.

My goal is to replace a file in the directory. To do this I figures I should first remove the entry and then add a new one.

I am facing a problem when trying to remove an entry. After executing RemoveEntries(), the entry is still there. I can check because after running, the number of entries didn't change. However, RemoveEntries() is returning true every time.

            ZipStorer zip = ZipStorer.Open(idmlPath, FileAccess.Write);

            List<ZipStorer.ZipFileEntry> removeList = new List<ZipStorer.ZipFileEntry>();
            // Look for the desired file to replace
            foreach (ZipStorer.ZipFileEntry entry in zip.ReadCentralDir())
            {
                if (Path.GetFileName(entry.FilenameInZip) == Path.GetFileName(archivePath))
                {
                    removeList.Add(entry);
                }
            }
            if (removeList.Count > 0)
            {
                bool result = ZipStorer.RemoveEntries(ref zip, removeList);
            }

            zip.Close();

not sure if this is a bug or I am doing something wrong. Assuming that the ZipStorer object should be opened with write access.