[
  {
    "Id": "810853",
    "ThreadId": "348738",
    "Html": "\r\n<p>Hi,</p>\r\n<p>&nbsp; Just starting to use DotNetZip library and hoping I am just overlooking something obvious. &nbsp;I am compressing text on my server, then sending it to a client for decompression. &nbsp;I don't want to use files, so I've been using memory streams.\r\n &nbsp;The problem I am having is that when I try do get the data using ZipInputStream it does not fill the buffer. &nbsp;I can see the compressed string is getting to the client, but can't uncompress it properly.</p>\r\n<p>&nbsp;</p>\r\n<p>Here is the compression code:</p>\r\n<p></p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre>        <span style=\"color:blue\">public</span> <span style=\"color:blue\">string</span> Compress(<span style=\"color:blue\">string</span> text)\r\n        {\r\n            <span style=\"color:blue\">byte</span>[] buffer = Encoding.UTF8.GetBytes(text);\r\n            MemoryStream ms = <span style=\"color:blue\">new</span> MemoryStream();\r\n\r\n            <span style=\"color:blue\">using</span> (ZipOutputStream zip = <span style=\"color:blue\">new</span> ZipOutputStream(ms))\r\n            {\r\n                zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;\r\n                zip.Write(buffer, 0, buffer.Length);\r\n            }\r\n\r\n            ms.Position = 0;\r\n            MemoryStream outStream = <span style=\"color:blue\">new</span> MemoryStream();\r\n\r\n            <span style=\"color:blue\">byte</span>[] compressed = <span style=\"color:blue\">new</span> <span style=\"color:blue\">byte</span>[ms.Length];\r\n            ms.Read(compressed, 0, compressed.Length);\r\n\r\n            <span style=\"color:blue\">byte</span>[] gzBuffer = <span style=\"color:blue\">new</span> <span style=\"color:blue\">byte</span>[compressed.Length &#43; 4];\r\n            System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);\r\n            System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);\r\n\r\n            <span style=\"color:blue\">return</span> Convert.ToBase64String(gzBuffer);\r\n        }\r\n</pre>\r\n</div>\r\n<p></p>\r\n<p>And, the decompression code:</p>\r\n<p></p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre>    <span style=\"color:blue\">public</span> <span style=\"color:blue\">string</span> Decompress(<span style=\"color:blue\">string</span> compressedText)\r\n\r\n    {\r\n        <span style=\"color:blue\">byte</span>[] compressedBuffer = Convert.FromBase64String(compressedText);\r\n\r\n        <span style=\"color:blue\">using</span> (MemoryStream ms = <span style=\"color:blue\">new</span> MemoryStream())\r\n        {\r\n            <span style=\"color:blue\">int</span> msgLength = BitConverter.ToInt32(compressedBuffer, 0);\r\n            ms.Write(compressedBuffer, 4, compressedBuffer.Length - 4);\r\n\r\n            <span style=\"color:blue\">byte</span>[] buffer = <span style=\"color:blue\">new</span> <span style=\"color:blue\">byte</span>[msgLength];\r\n\r\n            ms.Position = 0;\r\n            <span style=\"color:blue\">using</span> (ZipInputStream zip = <span style=\"color:blue\">new</span> ZipInputStream(ms))\r\n            {\r\n                zip.Read(buffer, 0, buffer.Length);\r\n            }\r\n\r\n            <span style=\"color:blue\">return</span> Encoding.UTF8.GetString(buffer);\r\n        }\r\n    }\r\n</pre>\r\n</div>\r\n<p></p>\r\n<p>What I'm seeing is when I get to the ZipInputStream portion, the memory stream (ms) has data, but after the zip.Read() the buffer is still empty. &nbsp;Anyone see what I am doing wrong?</p>\r\n<p>&nbsp;</p>\r\n<p>Thanks,</p>\r\n<p>Michael</p>\r\n",
    "PostedDate": "2012-03-15T07:24:22.01-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]