[
  {
    "Id": "1421947",
    "ThreadId": "636159",
    "Html": "Hi, great work on this.<br />\n<br />\nI'm having a problem with the GZipStream class. It is not compressing properly. On a certain input of about 56K in size, its returning a Stream of 10 bytes when compressed and 0 bytes when decompressed. I just want to know if this is a bug or if I'm using the class incorrectly.<br />\n<br />\nHere is the code:-<br />\n<pre><code>    Public Function CompressBytes(ByVal bytes As Byte()) As Byte()\n        Using ms As New MemoryStream(bytes)\n            Using compressedMs As New MemoryStream\n                Using gz As New GZipStream(compressedMs, CompressionMode.Compress)\n                    Dim buffer As Byte() = New Byte(1000) {}\n\n                    Dim bytesRead As Integer = ms.Read(buffer, 0, buffer.Length)\n\n                    Do Until bytesRead = 0\n                        gz.Write(buffer, 0, bytesRead)\n\n                        bytesRead = ms.Read(buffer, 0, buffer.Length)\n                    Loop\n\n                    Return compressedMs.ToArray\n                End Using\n            End Using\n        End Using\n    End Function\n\n    Public Function DecompressBytes(ByVal bytes As Byte()) As Byte()\n        Using ms As New MemoryStream\n            Using compressedMs As New MemoryStream(bytes)\n                Using gz As New GZipStream(compressedMs, CompressionMode.Decompress)\n\n                    Dim buffer As Byte() = New Byte(1000) {}\n\n                    Dim bytesRead As Integer = gz.Read(buffer, 0, buffer.Length)\n\n                    Do Until bytesRead = 0\n                        ms.Write(buffer, 0, bytesRead)\n\n                        bytesRead = gz.Read(buffer, 0, buffer.Length)\n                    Loop\n\n\n                    Return ms.ToArray\n\n                End Using\n            End Using\n        End Using\n\n\n    End Function\n</code></pre>\n\n",
    "PostedDate": "2015-05-01T00:03:24.143-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "1422076",
    "ThreadId": "636159",
    "Html": "Ok I solved it. It seems the GZipStream must be closed before reading the compressed stream for the compression to work properly.<br />\n",
    "PostedDate": "2015-05-01T16:23:21.05-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": "2015-05-01T16:27:51.88-07:00"
  }
]