[
  {
    "Id": "527912",
    "ThreadId": "236291",
    "Html": "\r\n<p>I haven't a clue what I'm doing wrong.&nbsp; I'm trying to create a zip file of a LOT (65,000&#43;) of small files, so I wanted to multi-thread if possible.&nbsp; The problem is the zip it creates all the files are 0 bytes.&nbsp; I pretty much copied the code\r\n from one of your examples, but it isn't working.&nbsp; A little help please!<br>\r\n<br>\r\nI already had a simple .zip option working, but it took quite a long time so I wanted to try to use a multi-threaded option.</p>\r\n<p>Thanks Much!</p>\r\n<p>&nbsp;</p>\r\n<hr>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre><span style=\"color:green\">' Create List of Files to Zip</span>\r\n<span style=\"color:blue\">Dim</span> FilesToZip <span style=\"color:blue\">As</span> <span style=\"color:blue\">New</span> ArrayList\r\n<span style=\"color:blue\">Dim</span> FilterList() <span style=\"color:blue\">As</span> <span style=\"color:blue\">String</span> = {<span style=\"color:#a31515\">&quot;*.txt&quot;</span>, <span style=\"color:#a31515\">&quot;*.properties&quot;</span>}\r\nFilesToZip.AddRange(Directory.GetFiles(ServerWorldPath, <span style=\"color:#a31515\">&quot;*.*&quot;</span>, SearchOption.AllDirectories))\r\n<span style=\"color:blue\">For</span> <span style=\"color:blue\">Each</span> Filter <span style=\"color:blue\">As</span> <span style=\"color:blue\">String</span> <span style=\"color:blue\">In</span> FilterList\r\n     FilesToZip.AddRange(Directory.GetFiles(<span style=\"color:blue\">My</span>.Settings.strHey0ModFolder, Filter, SearchOption.TopDirectoryOnly))\r\n<span style=\"color:blue\">Next</span>\r\n\r\n<span style=\"color:green\">' Zip the Files</span>\r\n<span style=\"color:blue\">Using</span> Output <span style=\"color:blue\">As</span> ZipOutputStream = <span style=\"color:blue\">New</span> ZipOutputStream(BackupFilename)\r\n     Output.CompressionLevel = Zlib.CompressionLevel.<span style=\"color:blue\">Default</span><br>     Output.EnableZip64 = Zip64Option.Always\r\n     Output.ParallelDeflateThreshold = 0\r\n     <span style=\"color:blue\">For</span> <span style=\"color:blue\">Each</span> inputFile <span style=\"color:blue\">As</span> <span style=\"color:blue\">String</span> <span style=\"color:blue\">In</span> FilesToZip\r\n          Console.WriteLine(inputFile)\r\n          Output.PutNextEntry(inputFile)\r\n          <span style=\"color:blue\">Using</span> Input <span style=\"color:blue\">As</span> FileStream = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)\r\n               <span style=\"color:blue\">Dim</span> n <span style=\"color:blue\">As</span> <span style=\"color:blue\">Integer</span>\r\n               <span style=\"color:blue\">Dim</span> buffer <span style=\"color:blue\">As</span> <span style=\"color:blue\">Byte</span>() = <span style=\"color:blue\">New</span> <span style=\"color:blue\">Byte</span>(2048) {}\r\n               <span style=\"color:blue\">Do</span> <span style=\"color:blue\">While</span> (n = Input.Read(buffer, 0, buffer.Length) &gt; 0)\r\n                    Output.Write(buffer, 0, n)\r\n               <span style=\"color:blue\">Loop</span>\r\n          <span style=\"color:blue\">End</span> <span style=\"color:blue\">Using</span>\r\n     <span style=\"color:blue\">Next</span>\r\n<span style=\"color:blue\">End</span> <span style=\"color:blue\">Using</span></pre>\r\n</div>\r\n",
    "PostedDate": "2010-11-28T09:28:26.317-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "529098",
    "ThreadId": "236291",
    "Html": "\r\n<p>I don't know what the problem is; it could be a bug in the library.</p>\r\n<p>But using parallel deflation in your scenario won't speed things up. Parallel deflation will speed things up if you have files that are larger than... say, 32k or 64k at a minimum. This is because this is the default size of the moving window in the DEFLATE\r\n implementation in the DotNetZip library.&nbsp; If you have lots of &quot;small&quot; files, where small means less than 16k, then using parallel deflation will be detrimental to performance. I think this is all explained in the documentation.</p>\r\n<p>Check it out.</p>\r\n<p>&nbsp;</p>\r\n",
    "PostedDate": "2010-11-30T15:21:40.467-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "529161",
    "ThreadId": "236291",
    "Html": "\r\n<p>These are small files and LOTS of them...&nbsp; The folder I'm compressing contains:<br>\r\n72,487 files &amp; 4,161 folders -- Yes you read the correctly.&nbsp;&nbsp;&nbsp; The files are ~3-4kb each</p>\r\n<p>As I couldn't get the above code to work, using this until I can find a better solution:</p>\r\n<p>&nbsp;</p>\r\n<hr>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre>        <span style=\"color:green\">' Create Zip of World Files</span>\r\n        <span style=\"color:blue\">Using</span> ZipF <span style=\"color:blue\">As</span> <span style=\"color:blue\">New</span> ZipFile(ZipFileName)\r\n            ZipF.CompressionLevel = Zlib.CompressionLevel.<span style=\"color:blue\">Default</span>\r\n            ZipF.UseZip64WhenSaving = Zip64Option.AsNecessary\r\n            ZipF.ParallelDeflateThreshold = 0\r\n            ZipF.BufferSize = 4096\r\n            ZipF.AddDirectory(ServerWorldPath, ServerWorldName)\r\n            ZipF.AddSelectedFiles(<span style=\"color:#a31515\">&quot;*.txt&quot;</span>, <span style=\"color:blue\">My</span>.Settings.strHey0ModFolder, <span style=\"color:#a31515\">&quot;&quot;</span>, <span style=\"color:blue\">False</span>)\r\n            ZipF.AddSelectedFiles(<span style=\"color:#a31515\">&quot;*.properties&quot;</span>, <span style=\"color:blue\">My</span>.Settings.strHey0ModFolder, <span style=\"color:#a31515\">&quot;&quot;</span>, <span style=\"color:blue\">False</span>)\r\n            ZipF.Save()\r\n        <span style=\"color:blue\">End</span> <span style=\"color:blue\">Using</span>\r\n\r\n        <span style=\"color:green\">' Print File Info</span>\r\n        <span style=\"color:blue\">Dim</span> fi <span style=\"color:blue\">As</span> <span style=\"color:blue\">New</span> FileInfo(ZipFileName)\r\n        stdIn.WriteLine(<span style=\"color:#a31515\">&quot;say * Zipping Finished - Size: &quot;</span> &amp; Math.Round(fi.Length / 1024 ^ 2, 0, MidpointRounding.ToEven) &amp; <span style=\"color:#a31515\">&quot; Mb *&quot;</span>)<br><hr>&nbsp;<br>Now I would love to get more threads working to speed things up, I only see 20-25% CPU usage when it is zipping.  Now with 7zip using Deflate64 &amp; 4 threads it uses 100% and finishes very quickly!<br><br>DotNetZip (1 Thread): 81 seconds<br>7zip (4 Threads): 14 seconds</pre>\r\n</div>\r\n<p>&nbsp;</p>\r\n",
    "PostedDate": "2010-11-30T18:20:41.637-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "530723",
    "ThreadId": "236291",
    "Html": "\r\n<p>yep, there's a big opportunity for efficiency if I parallelize the zipping on a file-by-file basis.</p>\r\n<p>In v1.9, I created a parallel stream that can deflate large files much faster. This doesn't help when there are many many files. &nbsp;</p>\r\n<p>That's something I had hoped to address in v2.0.&nbsp; For now I don't have any good options for you, to decrease that 81 seconds.</p>\r\n<p>&nbsp;</p>\r\n",
    "PostedDate": "2010-12-03T08:28:44.19-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]