jaime-olivares / zipstorer

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

Remove last zip entry corrupts archive, sometimes. #29

Closed seecondmouse closed 3 years ago

seecondmouse commented 6 years ago

Excellent tool BTW. Comments in zip entries is a unique capability. A user of my software reports that his zip file gets corrupted when removing the last entry (Win 7, NET 4.0). I have not reproduced this in my testing, so I am puzzled - maybe a timing or access issue? I am not using streams. An ideas? Here is my code, which is nearly the same as in example:

// Function to delete one zip file entry, by matching a filename. All will be uppercase.

    private void RemoveOne(string aname)
    {
        List<ZipStorer.ZipFileEntry> removeList = new List<ZipStorer.ZipFileEntry>();
        // Look for the entry that matches the given name
        foreach (ZipStorer.ZipFileEntry entry in zipdir)
        {
            if (Path.GetFileName(entry.FilenameInZip) == aname)
            {
                removeList.Add(entry);
                break;
            }
        }
        // double check
        if (removeList.Count > 0)
        {
            ZipStorer.RemoveEntries(ref zip, removeList); // list is just one
            // the close and reopen is done within the removeentries method, but somehow not quite right?
        }
        // should be done. I think I need this.
        zipdir = zip.ReadCentralDir(); // needed? what happen when last entry is removed?
    }
seecondmouse commented 6 years ago

Discovered that an older version of Zipstorer.cs was used. Perhaps last release resolves this issue. But in new release, the isEmpty() and UpdateComment() methods are missing! Was there a compelling reason for removing these? I need both.