Unzipping ZLIB compressed portions of a binary file
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....
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.
Try using the DeflateStream instead, "ZLIB" does not automatically mean GZip.
精彩评论