1

I have encountered a problem with DeflateStream -- some of the data is being written repeatedly, to the end.

Here is the code:

Dim bytesin As Byte() = ... ' An array of compressed bytes
Dim bytesout As Byte()
Dim count As Integer

Using ms As New MemoryStream(bytesin)
    Using ds As New Compression.DeflateStream(ms, Compression.CompressionMode.Decompress)
        Using outputStream As New MemoryStream()
            Dim buffer As Byte() = New Byte(1024) {}
            While InlineAssignHelper(count, ds.Read(buffer, 0, buffer.Length)) > 0
                outputStream.Write(buffer, 0, count)
            End While
            bytesout = outputStream.ToArray
        End Using
    End Using
End Using

Dim fs As FileStream = File.OpenWrite("fws.swf")
fs.Write(bytesout, 0, bytesout.Length)
fs.Flush()
fs.Close()


Private Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
    target = value
    Return value
End Function

How could you explain this?

https://i.stack.imgur.com/d2ffF.png

UPDATE

I tried with Ionic.Zlib.ZlibStream and Ionic.Zlib.DeflateStream and I have got the same strange result.

Velcro
  • 546
  • 1
  • 8
  • 27
  • Probably not the reason for the problem you mention, but aren't you losing the data read by the second "ds.Read(buffer, 0, buffer.Length)"? – Iridium Aug 28 '11 at 21:05
  • I corrected the mistyping - it happened after multiple code changes. But that don't fix the problem. Thank you anyway. – Velcro Aug 29 '11 at 04:32
  • Not sure exactly why InlineAssignHelper does, but my guess is that last read in the loop the buffer isn't getting cleared and you're re-writing left over bytes. – JNappi Aug 30 '11 at 21:09
  • `InlineAssignHelper()` is an helper function which gives an equivalent to the `if ((myvar = (testme)) > 0)` C# syntax. `buffer` has a size of 1024 bytes; why does it repeat at a random value? That's the question! :) – Velcro Aug 31 '11 at 04:22
  • When changing the `buffer` size, repeats appears at the same file offset. – Velcro Aug 31 '11 at 04:28

0 Answers0