[
  {
    "Id": "126867",
    "ThreadId": "38259",
    "Html": "I'm trying to check zip file using this code, but get an exception (OutOfMemoryException)&nbsp;when I try to extract&nbsp;big files.<br>\r\nThere are other ways to check corrupted file?<br>\r\nThanks<br>\r\nsorry for my english :p<br>\r\n<span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">&nbsp;<span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">\r\n<p>Private </p>\r\n</span>\r\n<p>&nbsp;</p>\r\n</span>\r\n<p><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">Function</span></span><span style=\"font-size:10px\"> checkCRCZip(</span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">ByVal</span></span><span style=\"font-size:10px\"> filezip </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">As</span></span><span style=\"font-size:10px\"> </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">String</span></span><span style=\"font-size:10px\">, </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">ByVal</span></span><span style=\"font-size:10px\"> dir </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">As</span></span><span style=\"font-size:10px\"> </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">String</span></span><span style=\"font-size:10px\">) </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">As</span></span><span style=\"font-size:10px\"> </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">String</span></span><br>\r\nDim&nbsp;</p>\r\n</span>\r\n<p>&nbsp;</p>\r\n</span>\r\n<p><span style=\"font-size:10px\">ZipFileToCheck </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">As</span></span><span style=\"font-size:10px\"> </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">String</span></span><span style=\"font-size:10px\"> = filezip</span><span style=\"font-size:10px;color:#008000\"><span style=\"font-size:10px;color:#008000\"><br>\r\n</span></span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">Dim</span></span><span style=\"font-size:10px\"> mStream </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">As</span></span><span style=\"font-size:10px\"> MemoryStream<br>\r\n</span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">Dim</span></span><span style=\"font-size:10px\"> output </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">As</span></span><span style=\"font-size:10px\"> </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">String</span></span><span style=\"font-size:10px\"> = </span><span style=\"font-size:10px;color:#a31515\"><span style=\"font-size:10px;color:#a31515\">&quot;&quot;<br>\r\n</span></span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">Dim</span></span><span style=\"font-size:10px\"> zip </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">As</span></span><span style=\"font-size:10px\"> ZipFile = ZipFile.Read(ZipFileToCheck)<br>\r\n</span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">Dim</span></span><span style=\"font-size:10px\"> zEntry </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">As</span></span><span style=\"font-size:10px\"> ZipEntry<br>\r\n</span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\"><br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;Try<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">For</span></span><span style=\"font-size:10px\"> </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">Each</span></span><span style=\"font-size:10px\"> zEntry </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">In</span></span><span style=\"font-size:10px\"> Zip<br>\r\n</span><span style=\"font-size:10px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mStream = </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">New</span></span><span style=\"font-size:10px\"> MemoryStream()<br>\r\n</span><span style=\"font-size:10px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zEntry.Extract(mStream)&nbsp;<br>\r\n</span><span style=\"font-size:10px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output = </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">String</span></span><span style=\"font-size:10px\">.Format(</span><span style=\"font-size:10px;color:#a31515\"><span style=\"font-size:10px;color:#a31515\">&quot;0x{1:X8}&quot;</span></span><span style=\"font-size:10px\">, zEntry.FileName, zEntry.Crc32)<br>\r\n</span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Next&nbsp;&nbsp;<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">Catch</span></span><span style=\"font-size:10px\"> ex </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">As</span></span><span style=\"font-size:10px\"> BadReadException<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show(ex.Message.ToString)<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output = </span><span style=\"font-size:10px;color:#a31515\"><span style=\"font-size:10px;color:#a31515\">&quot;&quot;<br>\r\n</span></span><span style=\"font-size:10px\"></span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">&nbsp;&nbsp;&nbsp;&nbsp;Catch</span></span><span style=\"font-size:10px\"> ex </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">As</span></span><span style=\"font-size:10px\"> BadCrcException<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show(ex.Message.ToString)<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output = </span><span style=\"font-size:10px;color:#a31515\"><span style=\"font-size:10px;color:#a31515\">&quot;&quot;<br>\r\n</span></span><span style=\"font-size:10px\"></span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">&nbsp;&nbsp;&nbsp;&nbsp;End</span></span><span style=\"font-size:10px\"> </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">Try<br>\r\n<span style=\"font-size:10px\"><br>\r\ncheckCRCZip = output<br>\r\n</span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">End</span></span><span style=\"font-size:10px\"> </span><span style=\"font-size:10px;color:#0000ff\"><span style=\"font-size:10px;color:#0000ff\">Function\r\n<p>&nbsp;</p>\r\n<p>\r\n<p>&nbsp;</p>\r\n</span></span></span></span></p>\r\n<p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n",
    "PostedDate": "2008-10-22T06:07:27.85-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "126902",
    "ThreadId": "38259",
    "Html": "The most reliable way to &quot;check&quot; a zip file is to actually extract all the entries within it.&nbsp; <br>\r\nThere can be a corruption at any point in the file, and the only way to find out is to extract each entry. <br>\r\nThis validates the checksums and data sizes and so on.<br>\r\n<br>\r\nIn your case, you are extracting to a memory stream which keeps all file (entry) contents in memory. For large files this is a problem, and you get the out-of-memory exception.<br>\r\n<br>\r\nI think what you may want is a stream with no storage at all, a &quot;bit bucket&quot;.&nbsp;<br>\r\n<br>\r\nTry <a href=\"http://msdn.microsoft.com/en-us/library/system.io.stream.null(VS.80).aspx\">System.IO.Stream.Null</a> .&nbsp; <br>\r\n",
    "PostedDate": "2008-10-22T07:48:26.253-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "127114",
    "ThreadId": "38259",
    "Html": "I can't find Stream in VB2005. <br>\r\nThere are only StreamReader and StreamWriter.<br>\r\n<br>\r\nEDIT: Sorry, I find it :p<br>\r\n<br>\r\n",
    "PostedDate": "2008-10-22T23:49:37.163-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "127373",
    "ThreadId": "38259",
    "Html": "<p>Glad you found it. <br>\r\n<br>\r\nHere's some code for anyone else who wants to try this:&nbsp;</p>\r\n<pre>            If File.Exists(ZipToCheck) Then\r\n\r\n                Console.WriteLine(&quot;Checking the zip file: {0}&quot;, ZipToCheck)\r\n\r\n                Dim bitBucket As System.IO.Stream\r\n                bitBucket = System.IO.Stream.Null\r\n\r\n                Using zip As ZipFile = ZipFile.Read(ZipToCheck)\r\n                    Dim zEntry As ZipEntry\r\n\r\n                    Try\r\n                          For Each zEntry In Zip\r\n                              If NOT zEntry.IsDirectory Then \r\n                                  zEntry.Extract(bitBucket) \r\n                                  Console.WriteLine(&quot;  {0,-48}   0x{1:X8}&quot;, zEntry.FileName, zEntry.Crc32)\r\n                              End If\r\n                          Next  \r\n                    Catch ex As BadReadException\r\n                          Console.WriteLine(ex.Message.ToString)\r\n                    Catch ex As BadCrcException\r\n                          Console.WriteLine(ex.Message.ToString)\r\n                    End Try\r\n                End Using\r\n\r\n            Else\r\n                Console.WriteLine(&quot;The zip file '{0}' does not exist.&quot;, ZipToCheck)\r\n            End If\r\n</pre>\r\n<p>If you think it is valuable, I could add a method to the ZipFile class to do this. It could be a matter of adding an overload to the existing static ZipFile.IsZipFile() method. </p>\r\n<p>&nbsp;</p>\r\n",
    "PostedDate": "2008-10-23T17:28:03.46-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]