[
  {
    "Id": "249147",
    "ThreadId": "72933",
    "Html": "<p>I really hate to ask this, but I cannot find the answer from searching. When using ZlibStream to create a .zip file (actually appears in Windows as a zip folder), the file cannot be opened directly by Windows when one clicks on the file. What I want to do is continue to stream log information for hours to a zip file log. I want to then be able to open that file using Windows Explorer. Is this at all possible with DotNetZip?</p>\r\n<p>Thank you for your help and I am sorry if this question has been answered else where.</p>",
    "PostedDate": "2009-10-23T14:31:45.323-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "249171",
    "ThreadId": "72933",
    "Html": "<blockquote style=\"border:solid .1em #ccc;font-style:italic;margin:.25em 1em 0 1em;padding:0 .25em 0 .25em\"><strong>ChrisO wrote:</strong><br>\r\n<p>I really hate to ask this, but I cannot find the answer from searching. When using ZlibStream to create a .zip file (actually appears in Windows as a zip folder), the file cannot be opened directly by Windows when one clicks on the file.</p>\r\n</blockquote>\r\n<p>Hello Chris!&nbsp; no problem on the questions.</p>\r\n<p>You cannot produce a .ZIP file using ZlibStream, not without a lot of work.&nbsp; ZlibStream produces a zlib-compressed stream of data, or consumes a zlib-compressed stream of data. It's not the same thing as a zip file.&nbsp; That explains why Windows cannot open it when you click on it.</p>\r\n<blockquote style=\"border:solid .1em #ccc;font-style:italic;margin:.25em 1em 0 1em;padding:0 .25em 0 .25em\"><strong>ChrisO wrote:</strong><br>\r\n<p>What I want to do is continue to stream log information for hours to a zip file log. I want to then be able to open that file using Windows Explorer. Is this at all possible with DotNetZip?</p>\r\n</blockquote>\r\n<p>If you want to produce a <strong>zip file</strong>, you need to use the <a href=\"http://cheeso.members.winisp.net/DotNetZipHelp/html/547e4c24-4683-96df-036e-19bc34ba27e4.htm\">ZipFile</a> class, or the <a href=\"http://cheeso.members.winisp.net/DotNetZipHelp/html/776a5035-37e3-4fb2-d76e-0a52e1421581.htm\">ZipOutputStream</a> class.&nbsp; The ZipOutputStream is new for DotNetZip v1.9.&nbsp;</p>\r\n<p>If using the ZipFile class, I would use a <a href=\"http://cheeso.members.winisp.net/DotNetZipHelp/html/e20db3f7-587b-2457-3ea5-d25e7b1bf68d.htm\">WriteDelegate</a>, like this:</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Green\">// this method gets invoked during zip.Save()</span>\r\n<span style=\"color:Blue\">private</span> <span style=\"color:Blue\">void</span> WriteEntry (String filename, Stream output)\r\n{\r\n    <span style=\"color:Green\">// Write the log data here. This can take hours...</span>\r\n    <span style=\"color:Blue\">byte</span>[] logdata= <span style=\"color:Blue\">new</span> <span style=\"color:Blue\">byte</span>[1000];\r\n    <span style=\"color:Blue\">bool</span> done = <span style=\"color:Blue\">false</span>;\r\n    <span style=\"color:Blue\">while</span> (!done)\r\n    {\r\n        <span style=\"color:Green\">// obtain data to log here</span>\r\n        <span style=\"color:Blue\">int</span> n = FillLogData(logdata);\r\n        <span style=\"color:Green\">// stream it to the zip file here </span>\r\n        output.Write(logdata, 0, n); \r\n        <span style=\"color:Green\">//  use some criteria to decide when we're done</span>\r\n        <span style=\"color:Blue\">if</span> (n == 0) done = <span style=\"color:Blue\">true</span>;        \r\n    }\r\n}\r\n\r\n<span style=\"color:Blue\">private</span> <span style=\"color:Blue\">void</span> Run()\r\n{\r\n    <span style=\"color:Blue\">string</span> zipFileName = <span style=\"color:#A31515\">&quot;ZippedLog.zip&quot;</span>; \r\n    <span style=\"color:Blue\">string</span> zipEntryName = <span style=\"color:#A31515\">&quot;MyApplication.log&quot;</span>;\r\n    <span style=\"color:Blue\">using</span> (<span style=\"color:Blue\">var</span> zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n    {\r\n        zip.AddEntry(zipEntryName, WriteEntry);\r\n        zip.Save(zipFileName);\r\n    }\r\n}\r\n</pre>\r\n</div>\r\n<p>If using the ZipOutputStream, I would suggest something like this:</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">string</span> zipFileName = <span style=\"color:#A31515\">&quot;AppLog.zip&quot;</span>;\r\n<span style=\"color:Blue\">string</span> zipEntryName = <span style=\"color:#A31515\">&quot;MyApplication.log&quot;</span>;\r\n<span style=\"color:Blue\">using</span> (<span style=\"color:Blue\">var</span> raw = File.Open(zipFileName, FileMode.Create, FileAccess.ReadWrite ))\r\n{\r\n    <span style=\"color:Blue\">using</span> (<span style=\"color:Blue\">var</span> output= <span style=\"color:Blue\">new</span> ZipOutputStream(raw))\r\n    {\r\n        output.PutNextEntry(zipEntryName);\r\n        <span style=\"color:Green\">// Write the log data here. This can take hours...</span>\r\n        <span style=\"color:Blue\">byte</span>[] logdata= <span style=\"color:Blue\">new</span> <span style=\"color:Blue\">byte</span>[1000];\r\n        <span style=\"color:Blue\">bool</span> done = <span style=\"color:Blue\">false</span>;\r\n        <span style=\"color:Blue\">while</span> (!done)\r\n        {\r\n            <span style=\"color:Green\">// obtain data to log here</span>\r\n            <span style=\"color:Blue\">int</span> n = FillLogData(logdata);\r\n            <span style=\"color:Green\">// stream it to the zip file here </span>\r\n            output.Write(logdata, 0, n); \r\n            <span style=\"color:Green\">//  use some criteria to decide when we're done</span>\r\n            <span style=\"color:Blue\">if</span> (n == 0) done = <span style=\"color:Blue\">true</span>;        \r\n        }\r\n    }\r\n}\r\n</pre>\r\n</div>",
    "PostedDate": "2009-10-23T15:55:43.397-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "251390",
    "ThreadId": "72933",
    "Html": "<p>Thank you very much. The ZipOutputStream looks like it will do what I require. I do have one other question though. I have many threads and each one is creating its own log file. My question now is if I have a separate stream and ZipOutputStream instance for each thread will the library code have any problems with that?</p>\r\n<p>Thanks again.&nbsp;</p>",
    "PostedDate": "2009-10-29T14:35:16.78-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "251431",
    "ThreadId": "72933",
    "Html": "<p>No problem with multiple threads each doing their own zipping.&nbsp; The ZipOutputStream class itself is NOT multithreaded, so you need to make sure at most one thread is calling into it at a time.&nbsp; But if you have 5 threads and 5 ZipOutputStream instances, no problem.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-10-29T17:52:48.7-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]