[
  {
    "Id": "525292",
    "ThreadId": "235578",
    "Html": "\r\n<p>I am attempting to do a binary read of a file from within the ZIP archive using the following code :</p>\r\n<p>&nbsp;</p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre>MemoryStream inp = <span style=\"color:blue\">new</span> MemoryStream(100);\r\n\r\nString sZipPath = <span style=\"color:#a31515\">@&quot;data2.zip&quot;</span>;\r\n\r\nString sFileName = <span style=\"color:#a31515\">&quot;format.xml&quot;</span>;\r\n<span style=\"color:blue\">char</span>[] charArray;\r\n<span style=\"color:blue\">byte</span>[] byteArray;\r\n\r\n  <span style=\"color:blue\">using</span> (ZipFile zip = ZipFile.Read(sZipPath))\r\n      {\r\n          <span style=\"color:blue\">if</span> (zip.EntryFileNames.Contains(sFileName))\r\n          {\r\n           <span style=\"color:green\">// use the string indexer on the zip file</span>\r\n             zip[sFileName].Extract(inp);\r\n             byteArray = <span style=\"color:blue\">new</span> <span style=\"color:blue\">byte</span>[200];\r\n             <span style=\"color:blue\">int</span> i = inp.Read(byteArray, 0, 100);\r\n           }\r\n      }\r\n\r\n</pre>\r\n</div>\r\n<p>When stepping through the code the ZIP file is found and opened, the filename specified is located and the Memory stream is created with the contents of the file. The problem is with the &quot;Read&quot; method against the memory steam, currently it executes and populates\r\n the byteArray with a 100 occurrences of x'00' - not the content of the file.</p>\r\n<p>What am I doing wrong ?</p>\r\n<p>&nbsp;</p>\r\n",
    "PostedDate": "2010-11-22T06:23:29.33-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "525295",
    "ThreadId": "235578",
    "Html": "\r\n<p>I think you need to move to the start of yout &quot;inp&quot; stream before reading. At the moment your code extracts the compressed file to the stream, then reads the next 100 bytes after the end of that data.</p>\r\n<p>Try this:</p>\r\n<p><span style=\"color:green\">// use the string indexer on the zip file</span><br>\r\nzip[sFileName].Extract(inp);<br>\r\n<strong>inp.Position = 0;</strong><br>\r\nbyteArray = <span style=\"color:blue\">new</span> <span style=\"color:blue\">byte</span>[200];<br>\r\n<span style=\"color:blue\">int</span> i = inp.Read(byteArray, 0, 100);</p>\r\n<p>Cheers,</p>\r\n<p>M</p>\r\n",
    "PostedDate": "2010-11-22T06:30:04.493-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "525309",
    "ThreadId": "235578",
    "Html": "\r\n<p>Thanks for the quick response, your suggestion was correct. It's working great now.</p>\r\n<p>Richard</p>\r\n",
    "PostedDate": "2010-11-22T06:54:04.063-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]