[
  {
    "Id": "164554",
    "ThreadId": "49230",
    "Html": "I have embedded several .mht help files in my application. These files are unloaded to a help directory when the application first runs.<br>\r\nI would like to 'compress' these files before compiling them as embedded  resources. I would then like to un-Zip them in the stream <br>\r\nused for their final file location.<br>\r\nHow would this look in VB.net? \r\n",
    "PostedDate": "2009-03-04T14:22:54.79-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "164573",
    "ThreadId": "49230",
    "Html": "<p>I'm currenly using the following method to 'unpack' my help files ...</p>\r\n<p><span style=\"font-size:13px;color:#0000ff\">Private</span><span style=\"font-size:13px\"> </span><span style=\"font-size:13px;color:#0000ff\">Sub</span><span style=\"font-size:13px\"> RehydrateResourceToFile(</span><span style=\"font-size:13px;color:#0000ff\">ByVal</span><span style=\"font-size:13px\"> resourceName </span><span style=\"font-size:13px;color:#0000ff\">As</span><span style=\"font-size:13px\"> </span><span style=\"font-size:13px;color:#0000ff\">String</span><span style=\"font-size:13px\">, _<br>\r\n                                                                    </span><span style=\"font-size:13px;color:#0000ff\">ByVal</span><span style=\"font-size:13px\"> FileName </span><span style=\"font-size:13px;color:#0000ff\">As</span><span style=\"font-size:13px\"> </span><span style=\"font-size:13px;color:#0000ff\">String</span><span style=\"font-size:13px\">)<br>\r\n</span><span style=\"font-size:13px;color:#0000ff\">    Dim</span><span style=\"font-size:13px\"> buffer </span><span style=\"font-size:13px;color:#0000ff\">As</span><span style=\"font-size:13px\"> </span><span style=\"font-size:13px;color:#0000ff\">Byte</span><span style=\"font-size:13px\">()<br>\r\n</span><span style=\"font-size:13px;color:#0000ff\">    Dim</span><span style=\"font-size:13px\"> stream </span><span style=\"font-size:13px;color:#0000ff\">As</span><span style=\"font-size:13px\"> Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)</span><span style=\"font-size:13px;color:#0000ff\"><br>\r\n   Using</span><span style=\"font-size:13px\"> reader </span><span style=\"font-size:13px;color:#0000ff\">As</span><span style=\"font-size:13px\"> </span><span style=\"font-size:13px;color:#0000ff\">New</span><span style=\"font-size:13px\"> BinaryReader(stream)<br>\r\n            buffer = reader.ReadBytes(</span><span style=\"font-size:13px;color:#0000ff\">CInt</span><span style=\"font-size:13px\">(stream.Length))<br>\r\n            reader.Close()<br>\r\n</span><span style=\"font-size:13px;color:#0000ff\">    End</span><span style=\"font-size:13px\"> </span><span style=\"font-size:13px;color:#0000ff\">Using <br>\r\n    </span><span style=\"font-size:13px;color:#0000ff\">Using</span><span style=\"font-size:13px\"> output </span><span style=\"font-size:13px;color:#0000ff\">As</span><span style=\"font-size:13px\"> </span><span style=\"font-size:13px;color:#0000ff\">New</span><span style=\"font-size:13px\"> FileStream(FileName, FileMode.Create)<br>\r\n            output.Write(Buffer, 0, Buffer.Length)<br>\r\n            output.Close()<br>\r\n</span><span style=\"font-size:13px;color:#0000ff\">    End</span><span style=\"font-size:13px\"> </span><span style=\"font-size:13px;color:#0000ff\">Using<br>\r\n</span><span style=\"font-size:13px;color:#0000ff\">End</span><span style=\"font-size:13px\"> </span><span style=\"font-size:13px;color:#0000ff\">Sub\r\n<p> </p>\r\n<p> </p>\r\n</span></p>\r\n<p>&nbsp;</p>\r\n<p> </p>\r\n<p> </p>\r\n",
    "PostedDate": "2009-03-04T15:02:33.327-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "164600",
    "ThreadId": "49230",
    "Html": "couple things.<br>\r\nfirst, are you sure that the .mht file (or compiled help or whatever) is compressible?   It could be that it is already in a compressed format, which means runnnig it through DotNetZip will not compress it further.   It's worth checking. <br>\r\n<br>\r\nNext - if you are storing your file as an embedded resource, and you want to unzip it with DotNetZip, you do not need to save the compressed thing to a file first.  You can unzip as you read  the bytes from the embedded resource, into the zip file.  Then just extract the files from there. <br>\r\n<br>\r\nI can provide code if you like.<br>\r\n<br>\r\n",
    "PostedDate": "2009-03-04T16:27:42.53-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "164613",
    "ThreadId": "49230",
    "Html": "Thanks for your quick response.  I'll definately support your cause ...<br>\r\nYes, I have tested the compression of these htlm files. <br>\r\nI author them in MSWord and I present them in a Browser control in a WinForm app.<br>\r\nOn average they compress to half of the original size.<br>\r\nI've read all of your help file and I think I understand the technology. <br>\r\nThe help files mention that you can compress to and from Streams but I have yet to see any example that would <br>\r\nhelp my situation.  Would I replace my BinaryReader in the example above? Or, would I replace the FileStream?<br>\r\nWould I be better served just using System.IO.Compresssion?<br>\r\nAny example would be great.<br>\r\nThanks again\r\n",
    "PostedDate": "2009-03-04T18:07:58.037-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "164633",
    "ThreadId": "49230",
    "Html": "You could use System.IO.Compression.DeflateStream - it gives ok compression, and it is guaranteed, built in.  Compared to other deflate libraries, it doesn't compress as well.  A while back people asked me to move off of System.IO.Compression for just that reason.  So today, the DotNetZip has its own DeflateStream.  But System.IO.Compression may be good enough for you.  It's certainly easy -no need to repackage a library.  The space savings from not redistributing Ionic.Zip.dll (about 370k) may more than make up for the poorer compression you get from System.IO.Compression. <br>\r\n<br>\r\nI would say, use DeflateStream, or just a simple stream compressor, if you are dealing with one or two files at a time.  A zip archive is better if you are packing up a larger number of files together.  <br>\r\n<br>\r\nTo use the DeflateStream , you would do something like this: <br>\r\n<pre>    Dim working As Byte() = New Byte(4096)\r\n    Dim n As Integer = 1\r\n    Using input As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)\r\n        Using decompressor As Stream = New DeflateStream(input, CompressionMode.Decompress, True)\r\n              Using output As FileStream = File.Create(Me._DecompressedFile)\r\n                  Do While (n &lt;&gt; 0)\r\n                      n = decompressor.Read(working, 0, working.Length)\r\n                      If (n &gt; 0) Then\r\n                          output.Write(working, 0, n)\r\n                      End If\r\n                  Loop\r\n              End Using\r\n        End Using\r\n    End Using\r\n</pre>\r\n<p>The result is a file, by the name stored in _DecompressedFile, on your disk. It is the decompressed version of whatever it was you embedded as a resource. </p>\r\n<p>This means you have to compress the thing before embedding it, of course. Which you would do with code that sort of looks like the above, but slightly different: </p>\r\n<pre>    Using input As Stream = File.OpenRead(Me._FileToCompress)\r\n        Using output As FileStream = File.Create(Me._CompressedFile)\r\n            Using compressor As Stream = New DeflateStream(output, CompressionMode.Compress, True)\r\n                Dim working As Byte() = New Byte(4096)\r\n                Dim n As Integer = -1\r\n                Do While (n &lt;&gt; 0)\r\n                    If (n &gt; 0) Then\r\n                        compressor.Write(working, 0, n)\r\n                    End If\r\n                    n = input.Read(working, 0, working.Length)\r\n                Loop\r\n            End Using\r\n        End Using\r\n    End Using\r\n</pre>\r\n<p>You could maybe do that as a pre-build step in Visual Studio, before embedding the resource. <br>\r\n<br>\r\nIf you want to use DotNetZip and do the zipfile thing, I can show you that as well.  let me know.<br>\r\n<br>\r\nOtherwise, Good luck! </p>\r\n",
    "PostedDate": "2009-03-04T20:04:56.357-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]