[
  {
    "Id": "201554",
    "ThreadId": "59533",
    "Html": "<p>Hi Guys,</p>\r\n<p>I have this code that was working with the inbuilt gzip compression but as the ratio was appalling I decided to give DotNetZip a try instead. I am compressing HTML into a SQLite DB so I would expect the compression ratio to be very good.</p>\r\n<p>I have compiled the following code by following various examples but to be honest I don't really understand it so I can't tell what the issue is.</p>\r\n<p>I am able to deflate the string &quot;hello world&quot; and then inflate it back to &quot;hello world&quot; so functionally it seems fine, but with inbuilt compression turned on my db goes from 7.25mb to 7.23mb. And with DotNetZip compression my db went to 7.89mb, so I am now really confused.</p>\r\n<p>&nbsp;</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">Imports</span> System.IO.Compression<br><span style=\"color:Blue\">Imports</span> System.Text<br><span style=\"color:Blue\">Imports</span> System.IO<br><span style=\"color:Blue\">Imports</span> Ionic<br><br><span style=\"color:Blue\">Public</span> <span style=\"color:Blue\">Class</span> ZipString<br>    <span style=\"color:Blue\">Public</span> <span style=\"color:Blue\">Shared</span> <span style=\"color:Blue\">Function</span> Deflate(<span style=\"color:Blue\">ByVal</span> text <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span>) <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span><br>        <span style=\"color:Blue\">Dim</span> buffer <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">Byte</span>() = Encoding.UTF8.GetBytes(text)<br>        <span style=\"color:Blue\">Dim</span> ms <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">New</span> MemoryStream()<br>        <span style=\"color:Green\">'Using zip As New GZipStream(ms, CompressionMode.Compress, True)</span><br>        <span style=\"color:Blue\">Using</span> Zip <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">New</span> Ionic.Zlib.ZlibStream(ms, _<br>            Zlib.CompressionMode.Compress, Zlib.CompressionLevel.BEST_SPEED, <span style=\"color:Blue\">True</span>)<br>            Zip.Write(buffer, 0, buffer.Length)<br>        <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span><br><br>        ms.Position = 0<br>        <span style=\"color:Blue\">Dim</span> outStream <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">New</span> MemoryStream()<br><br>        <span style=\"color:Blue\">Dim</span> compressed <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">Byte</span>() = <span style=\"color:Blue\">New</span> <span style=\"color:Blue\">Byte</span>(ms.Length - 1) {}<br>        ms.Read(compressed, 0, compressed.Length)<br><br>        <span style=\"color:Blue\">Dim</span> gzBuffer <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">Byte</span>() = <span style=\"color:Blue\">New</span> <span style=\"color:Blue\">Byte</span>(compressed.Length + 3) {}<br>        System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length)<br>        System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4)<br>        <span style=\"color:Blue\">Return</span> Convert.ToBase64String(gzBuffer)<br>    <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Function</span><br><br>    <span style=\"color:Blue\">Public</span> <span style=\"color:Blue\">Shared</span> <span style=\"color:Blue\">Function</span> Inflate(<span style=\"color:Blue\">ByVal</span> compressedText <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span>) <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span><br>        <span style=\"color:Blue\">Dim</span> gzBuffer <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">Byte</span>() = Convert.FromBase64String(compressedText)<br>        <span style=\"color:Blue\">Using</span> ms <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">New</span> MemoryStream()<br>            <span style=\"color:Blue\">Dim</span> msgLength <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">Integer</span> = BitConverter.ToInt32(gzBuffer, 0)<br>            ms.Write(gzBuffer, 4, gzBuffer.Length - 4)<br><br>            <span style=\"color:Blue\">Dim</span> buffer <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">Byte</span>() = <span style=\"color:Blue\">New</span> <span style=\"color:Blue\">Byte</span>(msgLength - 1) {}<br><br>            ms.Position = 0<br>            <span style=\"color:Green\">'Using zip As New GZipStream(ms, CompressionMode.Decompress)</span><br>            <span style=\"color:Blue\">Using</span> Zip <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">New</span> Ionic.Zlib.ZlibStream(ms, _<br>                             Zlib.CompressionMode.Decompress, Zlib.CompressionLevel.BEST_SPEED, <span style=\"color:Blue\">True</span>)<br>                Zip.Read(buffer, 0, buffer.Length)<br>            <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span><br><br>            <span style=\"color:Blue\">Return</span> Encoding.UTF8.GetString(buffer)<br>        <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span><br>    <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Function</span><br><span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Class</span><br><br><br><br>Any help is greatly appreciated.<br><br>Edit: Warning people do not copy and paste from word into this forum, it goes mental!<br><br></pre>\r\n</div>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-06-15T05:39:34.477-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "201613",
    "ThreadId": "59533",
    "Html": "<p>Turns out I was being dumb and looking in the wrong place I was passing it into my DB all wrong.</p>\r\n<p>&nbsp;</p>\r\n<p>That code actually works fine, see it as my contribution to the community :)</p>\r\n<p>&nbsp;</p>\r\n<p>Thanks for a great component.</p>",
    "PostedDate": "2009-06-15T08:13:55.617-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "201694",
    "ThreadId": "59533",
    "Html": "<p>great, Glad you figured it out.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-06-15T11:55:10.43-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "201975",
    "ThreadId": "59533",
    "Html": "<p>Hey, L33t, couple comments:</p>\r\n<p>The compression level is ignored when CompressionMode is Decompress.&nbsp; Therefore...this code:</p>\r\n<pre>Using Zip As New Ionic.Zlib.ZlibStream(ms, _\r\n                                       Zlib.CompressionMode.Decompress,_\r\n                                       Zlib.CompressionLevel.BEST_SPEED, _\r\n                                       True)\r\n    Zip.Read(buffer, 0, buffer.Length)\r\nEnd Using\r\n</pre>\r\n<p>...might be better written as:</p>\r\n<pre>Using Zip As New Ionic.Zlib.ZlibStream(ms, _\r\n                                       Zlib.CompressionMode.Decompress,_\r\n                                       True)\r\n    Zip.Read(buffer, 0, buffer.Length)\r\nEnd Using\r\n</pre>\r\n<p>Also, you know that by using BEST_SPEED, you are getting the least effective compression possible. You mentioned that the built-in DeflateStream wasn't effective for you. Using BEST_SPEED you may be missing out on 20% compression. Maybe worth testing to find out the difference between BEST_SPEED and BEST_COMPRESSION in your case.</p>\r\n<p>By the way, the enums BEST_SPEED and BEST_COMPRESSION change to BestSpeed and BestCompression in the current version of v1.8.</p>",
    "PostedDate": "2009-06-16T04:32:52.533-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]