DeflateStream 解压数据时重复字节

发布于 2024-12-01 23:31:32 字数 1139 浏览 0 评论 0原文

我遇到了 DeflateStream 的问题——一些数据被重复写入,直到最后。

这是代码:

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

你如何解释这一点?

https://i.sstatic.net/d2ffF.png

更新

我尝试使用 Ionic.Zlib.ZlibStream 和 Ionic.Zlib.DeflateStream ,但得到了同样奇怪的结果。

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.sstatic.net/d2ffF.png

UPDATE

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文