[
  {
    "Id": "593430",
    "ThreadId": "252932",
    "Html": "\r\n<p>Hi</p>\r\n<p>One of your example has</p>\r\n<pre><span>using</span> (ZipFile zip = ZipFile.Read(ExistingZipFile))<br><span>2</span>{<br><span>3</span>  ZipEntry e = zip[<span>&quot;MyReport.doc&quot;</span>];<br><span>4</span>  e.Extract(OutputStream);<br><span><br><br>When i use the above example like this<br></span>System.IO.MemoryStream s = new System.IO.MemoryStream();<br>entry.Extract(s);<br>readfrom(s);<br><br>readfrom(system.io.stream from)<br>{<br> int got;<br> while ((got = from.Read(buffer, 0, buffer.Length)) &gt; 0)<br> {<br>       <span style=\"color:#ff0000\">//////never enters the loop</span><br> }<br>}<br><br>The read doesn't succeed. Any help?</pre>\r\n",
    "PostedDate": "2011-04-07T04:41:09.863-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "594227",
    "ThreadId": "252932",
    "Html": "<p>yes - after writing to the stream, but before reading it, you must rewind it.&nbsp; You need to call s.Seek() to move the stream cursor to the beginning.</p>\r\n<p>in more detail: When you use DotNetZip to extract into a stream, it writes into the stream. This has the side effect of advancing the stream pointer. When the extraction (write) is finished, the pointer in the stream points to EOS - end of stream. If you try reading at that point, there is nothing there.&nbsp; You need to reset the pointer so that it refers to the beginning of the stream in order to read it.</p>\r\n<p>BUT - I don't know why you would want to extract into a MemoryStream, and then Read from the memorystream.&nbsp; By using that approach, You've added an additional step that isn't necessary.&nbsp; You're moving data around more than you need to, which takes longer, and consumes more memory.&nbsp; To eliminate the extra step, You can simply call ZipEntry.OpenReader() to get a Stream that you can read from directly.&nbsp; <a href=\"http://cheeso.members.winisp.net/DotNetZipHelp/html/4ef6405c-33ff-a8aa-1731-def3ec5cac24.htm\">http://cheeso.members.winisp.net/DotNetZipHelp/html/4ef6405c-33ff-a8aa-1731-def3ec5cac24.htm</a></p>\r\n<p>use it like this:</p>\r\n<pre>        using (ZipFile zip = ZipFile.Read(ExistingZipFile))\r\n        {\r\n            ZipEntry e = zip[\"MyReport.doc\"];\r\n            //e.Extract(OutputStream);\r\n            using (Stream s = e.OpenReader())\r\n            {\r\n                int got;\r\n                while ((got = from.Read(buffer, 0, buffer.Length)) &gt; 0) \r\n                {\r\n                    // buffer contains decompressed data from the entry\r\n                }\r\n            }\r\n        }        \r\n</pre>\r\n<p>&nbsp;</p>",
    "PostedDate": "2011-04-08T08:25:57.737-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "838147",
    "ThreadId": "252932",
    "Html": "<p>Hello,</p>\r\n<p>A good reason to reading back a previously extracted memory stream might be to process embedded ZIP files. I wish to list entries from large software distribution ZIP files, themselves containing some ZIP files from which I need to also list the entries (no extraction needed here).<span style=\"color: blue;\"></span><span style=\"color: blue;\">&nbsp;</span></p>\r\n<p>It seems that the stream provided by OpenReader() does not provide the seek abilities required by ZipFile.Read().</p>\r\n<p>\r\n<div style=\"color: black; background-color: white;\">\r\n<pre><span style=\"color: blue;\">using</span> (ZipFile mainZip = ZipFile.Read(mainZipFilePath))\r\n{\r\n  <span style=\"color: blue;\">foreach</span> (ZipEntry zipEntry <span style=\"color: blue;\">in</span> mainZip)\r\n  {\r\n    <span style=\"color: blue;\">if</span> (zipEntry.IsDirectory || !zipEntry.FileName.EndsWith(<span style=\"color: #a31515;\">\".zip\"</span>, StringComparison.OrdinalIgnoreCase))\r\n      <span style=\"color: blue;\">continue</span>;\r\n    Console.WriteLine(<span style=\"color: #a31515;\">\"Processing embedded ZIP file {0}\"</span>, zipEntry.FileName);\r\n    <span style=\"color: blue;\">using</span> (ZipFile embeddedZip = ZipFile.Read(zipEntry.OpenReader()))\r\n    { \r\n      <span style=\"color: blue;\">foreach</span> (ZipEntry embeddedEntry <span style=\"color: blue;\">in</span> embeddedZip)\r\n        Console.WriteLine(<span style=\"color: #a31515;\">\"- embedded ZIP entry found {0}\"</span>, embeddedEntry.FileName);\r\n    }\r\n  }\r\n}\r\n\r\nUnhandled Exception: Ionic.Zip.ZipException: Cannot read that <span style=\"color: blue;\">as</span> a ZipFile ---&gt;\r\nSystem.NotSupportedException: Specified method <span style=\"color: blue;\">is</span> not supported.\r\n   at Ionic.Crc.CrcCalculatorStream.Seek(Int64 offset, SeekOrigin origin) <span style=\"color: blue;\">in</span> CRC32.cs:line 783\r\n</pre>\r\n</div>\r\n</p>\r\n<p>Extracting to a memory stream works fine, although I end up extracting tens of megabytes of data.</p>\r\n<p>\r\n<div style=\"color: black; background-color: white;\">\r\n<pre>    Console.WriteLine(<span style=\"color: #a31515;\">\"Processing embedded ZIP file {0}\"</span>, zipEntry.FileName);\r\n    System.IO.MemoryStream ms = <span style=\"color: blue;\">new</span> System.IO.MemoryStream();\r\n    zipEntry.Extract(ms);\r\n    ms.Seek(0, SeekOrigin.Begin);\r\n    <span style=\"color: blue;\">using</span> (ZipFile embeddedZip = ZipFile.Read(ms))\r\n    {\r\n      <span style=\"color: blue;\">foreach</span> (ZipEntry embeddedEntry <span style=\"color: blue;\">in</span> embeddedZip)\r\n        Console.WriteLine(<span style=\"color: #a31515;\">\"- embedded ZIP entry found {0}\"</span>, embeddedEntry.FileName);\r\n    }\r\n\r\n</pre>\r\n</div>\r\n</p>",
    "PostedDate": "2012-05-18T07:23:28.68-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]