[
  {
    "Id": "163759",
    "ThreadId": "49024",
    "Html": "Hi, I've problem when I save compress file on steam, this is a simple code to reproduce the issue:<br>\r\n<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Save to stream<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Using zip As New Ionic.Zip.ZipFile<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.AddFileFromString(&quot;file.zip&quot;, &quot;&quot;, System.IO.File.ReadAllText(&quot;c:\\temp\\test.html&quot;))<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim s As New System.IO.MemoryStream()<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.Save(s)<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.IO.File.WriteAllText(&quot;c:\\temp\\test.html_1.zip&quot;, System.Text.Encoding.Default.GetString(s.ToArray))<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Using<br>\r\n<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Save to file<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Using zip As New Ionic.Zip.ZipFile<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.AddFile(&quot;c:\\temp\\test.html&quot;, &quot;&quot;)<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.Save(&quot;c:\\temp\\test.html_2.zip&quot;)<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Using<br>\r\n<br>\r\nThe test.html_1.zip seems corrupted and it's also twice bigger then test.html_2.zip..<br>\r\n",
    "PostedDate": "2009-03-03T02:09:32.483-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "163875",
    "ThreadId": "49024",
    "Html": "Hmmmm, yes I would bet you have experienced a few problems!<br>\r\n <br>\r\nFirst, what do you expect to get when calling System.Text.Encoding.Default.GetString() using s.ToArray() as the input?     The zip data contained within s.ToArray() is not an encoded string.  Calling GetString() on it will not produce a usable string; I suspect if you print out the result of that call, you will get a long series of question marks.  And then, writing that string (?????????????????????????) out to a file will not produce a valid zip file. It is just a series of question marks. <br>\r\n<br>\r\nWhat are you trying to accomplish, with that code? Can you explain in english? <br>\r\n<br>\r\nNext - the MemoryStream is disposable, and should be wrapped in a using clause. <br>\r\n<br>\r\nThis code will save a zip to a MemoryStream and then writes the content of that MemoryStream to a disk file. Notice there is no attempt to decode the zip file data into a string  with a call to Encoding.GetString().<br>\r\n<pre>Dim buffer As Byte() = Nothing\r\n' This will not scale very well!\r\nUsing ms As MemoryStream = New MemoryStream\r\n    Using zip As ZipFile = New ZipFile\r\n        zip.AddItem(NameOfFileOrDirectoryToZip)\r\n        zip.Save(ms)\r\n    End Using\r\n    buffer = ms.ToArray\r\nEnd Using\r\n\r\nUsing output As FileStream = File.Create(archiveName)\r\n    output.Write(buffer, 0, buffer.Length)\r\nEnd Using\r\n\r\n</pre>\r\nBut that approach is not very scalable. Suppose you have a zip file that is 1mb in size. Then you will have a 1mb buffer in memory. Large, but not too large. Now suppose you have a 2gb zip file. Will you retain a 2gb buffer in memory?  This approach works for small zip files but doesn't scale up well. <br>\r\nThe DotNetZip library can save zip files into a stream, or it can save to a file on disk.  You seem to be doing something in the middle - you write the data to a stream and then write it to a file. <br>\r\nWhat is it that you really want to do? What are you trying to accomplish? <br>\r\n<br>\r\nThere is a third problem in your code, something I don't understand at all.  You have this code: <br>\r\n<pre>zip.AddFileFromString(&quot;file.zip&quot;, &quot;&quot;, System.IO.File.ReadAllText(&quot;c:\\temp\\test.html&quot;))\r\n\r\n</pre>\r\nThis statement adds a new entry into the ZipFile instance; the entry is named &quot;file.zip&quot;. And the contents of that entry are obtained from a file called &quot;c:\\temp\\test.html&quot;. This does not make sense to me, for a couple reasons. First, you are inserting what is apparently an HTML file into an entry named &quot;file.zip&quot;. As above, using the .zip extension does not make it a zip file.  This is very confusing to me.  The content is still going to be HTML. Second, why use AddFileFromString() when the entry you want to add to the zip file, is in a file already? Why not just call AddFile? This would be more sensible, to me:\r\n<pre>zip.AddFile(&quot;c:\\temp\\test.html&quot;)\r\n\r\n</pre>\r\nWith that line of code, you are telling DotNetZip to add a file (&quot;c:\\temp\\test.html&quot;) to the ZipFile instance.   <br>\r\nRegarding that call to AddFileFromString(), I will ask the same question I asked above: what are you trying to accomplish? <br>\r\nHave you read the documentation for DotNetZip? I've tried to be very thorough with it. <br>\r\n",
    "PostedDate": "2009-03-03T07:12:47.873-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]