[
  {
    "Id": "647714",
    "ThreadId": "266593",
    "Html": "\r\n<p>Hi,</p>\r\n<p>I have the following code:</p>\r\n<p><span style=\"font-size:x-small\"><span style=\"font-size:x-small\"></p>\r\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Main(string[] args)<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; curPosX = Console.CursorLeft;<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; curPosY = Console.CursorTop;<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (ZipFile zipFile = new ZipFile())<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zipFile.UseZip64WhenSaving = Zip64Option.Always;<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zipFile.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed;<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zipFile.SaveProgress &#43;= new EventHandler&lt;SaveProgressEventArgs&gt;(zipFile_SaveProgress);<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zipFile.AddFile(@&quot;C:\\TEMP\\speedtest_500MB.bin&quot;, &quot;backup&quot;);<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zipFile.Save(@&quot;C:\\TEMP\\speedtest_500MB.zip&quot;);<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>\r\n<p></p>\r\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void zipFile_SaveProgress(object sender, SaveProgressEventArgs e)<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (e.TotalBytesToTransfer != 0)<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.SetCursorPosition(curPosX, curPosY);<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;Writing entry {0} of {1}, currently at {2}kb of {3}kb&quot;, e.EntriesSaved, e.EntriesTotal, e.BytesTransferred /1024, e.TotalBytesToTransfer / 1024);<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>\r\n<p></p>\r\n</span></span>\r\n<p></p>\r\n<p>This code takes a binary file of 500 MB in size and compresses it. But when the temporary file has been created for the first time, it immediately clears out the file again and starts all over again. Just after the second time the temporary file will be\r\n renamed to the speedtest_500MB.zip.</p>\r\n<p>Is this normal behavior? Or am I doing something wrong?</p>\r\n<p>Regards,</p>\r\n<p>Marcel.</p>\r\n",
    "PostedDate": "2011-07-26T06:22:20.863-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "647999",
    "ThreadId": "266593",
    "Html": "<p>yes, the behavior you describe is expected.&nbsp; It's normal.&nbsp; (probably)</p>\r\n<p>There's a feature in the zip library that will store the file into the zip file \"uncompressed\", if \"compression\" increases the size of the file.&nbsp; This feature was added a long time ago, to combat the anomalous behavior of the builtin System.IO.Compression.DeflateStream, which, in some cases can increase the size of a file 40% or more. This happens with previously compressed data.&nbsp; Though DotNetZip no longer uses System.IO.Compression.DeflateStream - instead it uses its own managed ZLIB library for compression - and therefore the massive increases in size no longer are possible, the \"check for increase\" feature is still in there.&nbsp;&nbsp; It handles even small increases in size.</p>\r\n<p>Looking at your code I see that you are using \"Bestspeed\" for the compression level.&nbsp; This can in some cases result in a slightly larger \"compressed\" file than the original \"uncompressed\" file.&nbsp; It will happen only when the original file is not really \"uncompressed\" - it will happen when it is in some compressed format.&nbsp; So the behavior you describe is normal if you are dealing with a file that is already compressed.</p>\r\n<p>There's currently no way to turn off the \"retry if the filesize increases\" feature.</p>\r\n<p>I think if you raise the compression level to something better, you may avoid the problem. Conversely, if you know the file will not compress, you can specify CompressionLevel = None and the file will be stored directly, no attempt will be made to compress it.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2011-07-26T15:07:49.873-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "648177",
    "ThreadId": "266593",
    "Html": "Thanks!\r\n<div><br>\r\n</div>\r\n<div>Because I used a file with 500 MB of random bytes of data, there is nothing to compress, so indeed the size increases a little when you store it in a zipfile. I tried it again with a file that can be compressed and now it only does the compression once.\r\n<div><br>\r\n</div>\r\n<div>\r\n<div>2011/7/27 Cheeso <span dir=\"ltr\">&lt;<a href=\"mailto:notifications@codeplex.com\">notifications@codeplex.com</a>&gt;</span><br>\r\n<blockquote style=\"margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex\">\r\n<div>\r\n<p>From: Cheeso</p>\r\n<div>\r\n<p>yes, the behavior you describe is expected. It's normal. (probably)</p>\r\n<p>There's a feature in the zip library that will store the file into the zip file &quot;uncompressed&quot;, if &quot;compression&quot; increases the size of the file. This feature was added a long time ago, to combat the anomalous behavior of the builtin System.IO.Compression.DeflateStream,\r\n which, in some cases can increase the size of a file 40% or more. This happens with previously compressed data. Though DotNetZip no longer uses System.IO.Compression.DeflateStream - instead it uses its own managed ZLIB library for compression - and therefore\r\n the massive increases in size no longer are possible, the &quot;check for increase&quot; feature is still in there. It handles even small increases in size.</p>\r\n<p>Looking at your code I see that you are using &quot;Bestspeed&quot; for the compression level. This can in some cases result in a slightly larger &quot;compressed&quot; file than the original &quot;uncompressed&quot; file. It will happen only when the original file is not really &quot;uncompressed&quot;\r\n - it will happen when it is in some compressed format. So the behavior you describe is normal if you are dealing with a file that is already compressed.</p>\r\n<p>There's currently no way to turn off the &quot;retry if the filesize increases&quot; feature.</p>\r\n<p>I think if you raise the compression level to something better, you may avoid the problem. Conversely, if you know the file will not compress, you can specify CompressionLevel = None and the file will be stored directly, no attempt will be made to compress\r\n it.</p>\r\n<p></p>\r\n</div>\r\n<div>\r\n<p>Read the <a href=\"http://dotnetzip.codeplex.com/discussions/266593#post647999\" target=\"_blank\">\r\nfull discussion online</a>.</p>\r\n<p>To add a post to this discussion, reply to this email (<a href=\"mailto:DotNetZip@discussions.codeplex.com?subject=[DotNetZip:266593]\" target=\"_blank\">DotNetZip@discussions.codeplex.com</a>)</p>\r\n<p>To start a new discussion for this project, email <a href=\"mailto:DotNetZip@discussions.codeplex.com\" target=\"_blank\">\r\nDotNetZip@discussions.codeplex.com</a></p>\r\n<p>You are receiving this email because you subscribed to this discussion on CodePlex. You can\r\n<a href=\"https://dotnetzip.codeplex.com/discussions/266593/unsubscribe/\" target=\"_blank\">\r\nunsubscribe</a> on CodePlex.com.</p>\r\n<p>Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com</p>\r\n</div>\r\n</div>\r\n</blockquote>\r\n</div>\r\n<br>\r\n</div>\r\n</div>\r\n",
    "PostedDate": "2011-07-27T02:59:18.413-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "648243",
    "ThreadId": "266593",
    "Html": "<p>Ahh, right, random data will also be mostly incompressible.</p>\r\n<p>Compression - all algorithms - work by replacing repeated patterns with smaller \"encodings\"&nbsp;.&nbsp; Random data won't exhibit those patterns and therefore won't be highly compressible.</p>",
    "PostedDate": "2011-07-27T05:36:25.65-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]