This project is read-only.

Issue replacing contents of ZipEntry

Jul 22, 2010 at 2:43 AM


Consider the following code snippet

public void Process(Stream original, Stream modified)
    using (var zip = ZipFile.Read(original))
        for (var index = 0; index < _zip.Count; index++)
            var entry = _zip[index];
            if (entry.IsDirectory)

            const FileOptions options = FileOptions.DeleteOnClose | FileOptions.Encrypted;
            Stream stream = File.Create(Path.GetTempFileName(), 4096, options);
            // process stream
            zip.UpdateEntry(entry.FileName, stream);

UpdateEntry fails when a zip file has duplicate entries (like different document.doc and document.doc in the root).  The message is "System.ArgumentException: An item with the same key has already been added.". I can provide a test file created with 7zip, however, I don't see a way to attach it to this post. 

I only started looking at the source today and would appreciate any suggestions to fix this issue.  In addition, I'd like to suggest that the entry itself has a Replace/SetContents method taking just a stream, path, or byte array. This will allow one to pass in a temporary file and still keep name of the ZipEntry the same.  In fact, I don't care too much about the name of the entry, except that it must remain the same.