[
  {
    "Id": "281829",
    "ThreadId": "82043",
    "Html": "<p>Hi,</p>\r\n<p>Using DotNetZip 1.9.1.1.</p>\r\n<p>While adding an entry to an existing zip file containing approx. 9000 entries, my server shutdown unexpectedly.</p>\r\n<p>On reboot, I found out that the original file was corrupt:</p>\r\n<p>Ionic.Zip.BadReadException:&nbsp;&nbsp; ZipEntry::ReadHeader(): Bad signature (0x00000000) at position&nbsp; 0x00000000<br>&nbsp;&nbsp; at Ionic.Zip.ZipEntry.ReadHeader(ZipEntry ze, Encoding defaultEncoding)<br>&nbsp;&nbsp; at Ionic.Zip.ZipEntry.ReadEntry(ZipContainer zc, Boolean first)<br>&nbsp;&nbsp; at Ionic.Zip.ZipFile.ReadIntoInstance_Orig(ZipFile zf)<br>&nbsp;&nbsp; at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf)<br>&nbsp;&nbsp; at Ionic.Zip.ZipFile.Read(String fileName, TextWriter statusMessageWriter, Encoding encoding, EventHandler`1 readProgress)<br>&nbsp;&nbsp; at Ionic.Zip.ZipFile.Read(String fileName)</p>\r\n<p>In the same directory, I found the temporary file (DotNetZip-XXXXXX). After changing the extension to .zip, I can't seem to open it either. This is unexpected for me. I thought the temporary file was a copy of the zip file, with the new entry. Here is my expected behavior if the system shutdown during Save():</p>\r\n<p>- The original zip file is left untouched, and the DotNetZip-XXXXXX file is corrupt. (stopped while building the new file)</p>\r\n<p>OR</p>\r\n<p>- The original zip file is corrupt, and the DotNetZip-XXXXXX file is okay&shy;. (stopped while overwriting the original file)</p>\r\n<p>Here is the calling code:</p>\r\n<p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre>                <span style=\"color:Blue\">using</span> (ZipFile zip = ZipFile.Read(<span style=\"color:Blue\">this</span>.OutputFile))\r\n                {\r\n                    <span style=\"color:Blue\">try</span>\r\n                    {\r\n                        zip.ParallelDeflateThreshold = -1; <span style=\"color:Green\">//Do not multi-thread inner operations.</span>\r\n                        zip.BufferSize = 20480;\r\n                        zip.CompressionLevel = CompressionLevel.BestCompression;\r\n                        zip.UseZip64WhenSaving = Zip64Option.AsNecessary;\r\n                        zip.SaveProgress += <span style=\"color:Blue\">this</span>.SaveZipHandler;\r\n                        <span style=\"color:Blue\">foreach</span> (<span style=\"color:Blue\">var</span> entry <span style=\"color:Blue\">in</span> entries)\r\n                        {\r\n                            <span style=\"color:Green\">//Simply queue the right amount of entries.</span>\r\n                            zip.AddEntry(entry.EntryName, Stream.Null);\r\n                            _entriesToZip.Enqueue(entry);\r\n                        }\r\n                        zip.Save();\r\n                    }\r\n                    <span style=\"color:Blue\">finally</span>\r\n                    {\r\n                        zip.SaveProgress -= <span style=\"color:Blue\">this</span>.SaveZipHandler;\r\n                    }\r\n                }\r\n\r\n</pre>\r\n</div>\r\nSaveZipHandler opens a Stream to the file before saving each entry.</p>\r\n<p>Please tell be how DotNetZip is supposed to manage transactional zipping, and what is the behavior is the system shuts down during the save.</p>\r\n<p>Many thanks,</p>\r\n<p>Patrick</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-01-26T05:33:42.95-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "282047",
    "ThreadId": "82043",
    "Html": "<p>I don't know exactly what happened, but:</p>\r\n<p>- your expectation is correct regarding the behavior during savve.&nbsp;</p>\r\n<p>- the normal savve operation is for DotNetZip to save into a temp file, then rename the temporary file to the permanent name.&nbsp; But, If a problem occurs during the rename, you may be left with nothing.&nbsp; In other words there is a window of vulnerability, after the new zipfile has been written, and before the rename is complete.&nbsp; If you can't tolerate that vulnerability, then you should save to a new file name, and do the transactional rename yourself.</p>\r\n<p>- the exception message indicates to me that the original zip file was corrupt, before you tried to Save.&nbsp; Reading 00000000 at position 00000000 indicates either an empty file, or a file with all zeroes.&nbsp;&nbsp; This can happen if you run out of disk space or quota.&nbsp;</p>\r\n<p>- If the problem happened before the save, as your exception indicates, then I don't know why you had a temp file there.&nbsp; it must have been left over from a prior error.</p>",
    "PostedDate": "2010-01-26T15:08:04.963-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]