[
  {
    "Id": "239644",
    "ThreadId": "70358",
    "Html": "<p>Hi,</p>\r\n<p>I am attempting to compress and then decompress some byte arrays using the newest (beta) version of libraries.&nbsp; I am using the DeflateStream.&nbsp; I had this working in version 1.8 of the library, but upgraded to 1.9 (had some weird issues, possibly unrelated to this library, but I figured it couldn't hurt to try something new).&nbsp; There seems to be a bug that occurs when using the Read() function of the DeflateStream when I am decompressing.&nbsp; I have the following code:<br>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre>                <span style=\"color:Blue\">int</span> compressedLength;\r\n                <span style=\"color:Blue\">byte</span>[] bufferedBytes;\r\n\r\n                MemoryStream memoryStream = <span style=\"color:Blue\">new</span> MemoryStream(buffer.Array, buffer.Offset, buffer.Count);\r\n                DeflateStream deflateStream = <span style=\"color:Blue\">new</span> DeflateStream(memoryStream, CompressionMode.Decompress, <span style=\"color:Blue\">true</span>);\r\n                MemoryStream uncompressedStream = <span style=\"color:Blue\">new</span> MemoryStream();\r\n                \r\n                <span style=\"color:Blue\">int</span> readBytes = 0;\r\n                bufferedBytes = <span style=\"color:Blue\">new</span> <span style=\"color:Blue\">byte</span>[1024];\r\n                <span style=\"color:Blue\">while</span> ((readBytes = deflateStream.Read(bufferedBytes, 0, bufferedBytes.Length)) &gt; 0)\r\n                    uncompressedStream.Write(bufferedBytes, 0, readBytes);\r\n</pre>\r\n</div>\r\n</p>\r\n<p>As you can see, I am attempting to loop by 1024 byte increments and decompress an array of bytes (buffer.Array is a byte[]).&nbsp; The bug seems to manifest when the decompressed size of the byte array is smaller than 1024.&nbsp; So, if the input is maybe 293 bytes compressed, and would be maybe 417 bytes uncompressed, the Read() function returns 0 as the number of bytes read.&nbsp; But not always the case, ie, many times it works correctly and returns the number of bytes read even if it is less than 1024.&nbsp; But I can consistently reproduce this with the 293 bytes compressed to 417 bytes uncompressed.&nbsp; The interesting thing is that the DeflateStream correctly decompresses it, that is to say, after calling Read(), I can see that the DeflateStream.TotalIn is 293 and the DeflateStream.TotalOut is 417...&nbsp; But since the Read() returned 0, nothing ends up being written to the &quot;uncompressedStream&quot; variable, even though &quot;bufferedBytes&quot; actually contains the correct data.</p>\r\n<p>I am pretty sure that this is not the desired behavior, and has caused me some issues.&nbsp; I have found a workaround, which is to make my &quot;bufferedBytes&quot; array be of size Math.Min(1024, buffer.Count) instead of 1024.&nbsp; This basically eliminates cases where the size of &quot;bufferedBytes&quot; is greater than the decompressed byte array returned by Read().&nbsp; But I shouldn't have to do this.&nbsp; The updated line of code is:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\r\n<div style=\"color:Black;background-color:White\">\r\n<pre>               bufferedBytes = <span style=\"color:Blue\">new</span> <span style=\"color:Blue\">byte</span>[Math.Min(1024, buffer.Count)];\r\n</pre>\r\n</div>\r\n</p>\r\n<p>Any help would be appreciated.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-09-28T11:32:24.797-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "239860",
    "ThreadId": "70358",
    "Html": "This discussion has been copied to a work item. Click <a href=\"http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=8869\">here</a> to go to the work item and continue the discussion.",
    "PostedDate": "2009-09-28T23:39:35.243-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "239862",
    "ThreadId": "70358",
    "Html": "<p>Sounds like a bug.</p>\r\n<p>Can you upload the deflated (293-byte) file that causes the problem?&nbsp; Attach it to the workitem.&nbsp; (See the post on this discussion forum thread for the link).</p>\r\n<p>When you post the file I'll get it fixed.</p>",
    "PostedDate": "2009-09-28T23:41:35.05-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "239949",
    "ThreadId": "70358",
    "Html": "<p>I tried to reproduce this problem but couldn't.&nbsp;</p>\r\n<p>If you can send me a file that causes the problem, I'll be able to fix it.</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-09-29T05:45:51.687-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]