解压缩二进制文件的 ZLIB 压缩部分

发布于 2024-08-11 05:09:03 字数 1078 浏览 2 评论 0原文

我正在从 .Net 3.5 读取一个文件(Flash swf),该文件的标头表明文件/流的主体是否被压缩。但是,我遇到了问题 - 在将基本文件流重新包装到 GZipStream 中后,我收到一个异常,指出“GZip 标头中的幻数不正确。请确保您传入的是 GZip 流。”

虽然我可能不明白 SWF 是如何格式化的(Adobe 的文档仅指出主体“使用 ZLIB 开放标准进行压缩。ZLIB 库使用的数据格式由征求意见(RFC)描述” 1950 年至 1952 年的文档。”),也可能是我不理解 GZipStream 的工作原理。

所以我的问题是双重的: 1) 当收到已经读取的父流时,GZipStream 通常会正常工作吗?
2) GZipStream 是否可以处理以这种方式压缩的数据?如果没有,您是否建议使用其他开源库?

谢谢。

仅供参考,这是相关代码的片段(F#):

let reader= match signature with 
            |['F';'W';'S']-> //uncompresssed
                             reader
            |['C';'W';'S']->
                             let gzs= new System.IO.Compression.GZipStream(reader.BaseStream, System.IO.Compression.CompressionMode.Decompress)
                             new BinaryReader(gzs)
            |_-> failwith "something is invalid in this header"
let frameSB = List.nth ((reader.PeekChar()|>BitConverter.GetBytes)|>List.ofArray) 0 in
let frameSize = frameSB&&&31uy |> (+) 5uy |> fun fs-> fs+ 8uy-(fs%8uy) //rect data structure....

I'm reading a file(a flash swf) from .Net 3.5 that has a header which states whether the body of the file/Stream is compressed or not. However, I'm having problems-after I rewrap the basic File stream in a GZipStream, I get an exception stating that "The magic number in GZip header is not correct. Make sure you are passing in a GZip stream."

While it may be that I'm not understanding how the SWF is formatted(Adobe's documentation states only that the body is "compressed by using the ZLIB open standard. The data format that the ZLIB library uses is described by Request for Comments (RFCs) documents 1950 to 1952."), it may also be that I'm not understanding how GZipStream works.

So my question is twofold:
1) Will GZipStream generally work correctly when handed a parent stream that has already been read from?
2) Does GZipStream work with data compressed in this way? And if not, is there other open source lib you'd recommend using?

thanks.

FYI, here's the snipped of relevant code(F#):

let reader= match signature with 
            |['F';'W';'S']-> //uncompresssed
                             reader
            |['C';'W';'S']->
                             let gzs= new System.IO.Compression.GZipStream(reader.BaseStream, System.IO.Compression.CompressionMode.Decompress)
                             new BinaryReader(gzs)
            |_-> failwith "something is invalid in this header"
let frameSB = List.nth ((reader.PeekChar()|>BitConverter.GetBytes)|>List.ofArray) 0 in
let frameSize = frameSB&&&31uy |> (+) 5uy |> fun fs-> fs+ 8uy-(fs%8uy) //rect data structure....

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青春如此纠结 2024-08-18 05:09:03

DeflateStream 不需要 (120,-100) ZLIB 标头,也不会消耗后续的 Adler32。我有一些关于如何使 DeflateStream 匹配 java.util.zip此处。如果一切都失败了,还有一个 ZLib Java 端口的端口

DeflateStream doesn't want the (120,-100) ZLIB header, nor will it consume the subsequent Adler32. I have some notes about how to make the DeflateStream match the java.util.zip streams here. And if all else fails, there is a port of the Java port of ZLib around too.

小兔几 2024-08-18 05:09:03

尝试使用 DeflateStream 代替,“ZLIB”并不自动表示 GZip。

Try using the DeflateStream instead, "ZLIB" does not automatically mean GZip.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文