views:

180

answers:

2

Hi All-

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....
A: 

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

Lasse V. Karlsen
Thanks for the suggestion, but that one craps out with "Block length does not match with its complement."
Michael Kohout
Well, then it's time to dig into the flash format description.
Lasse V. Karlsen
A: 

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.

Steve Gilham
Thanks for the help Steve! The port of the port of ZLib seems to have done the trick! It makes sense, actually: the Flash Actionscript 3 compiler is written in java.
Michael Kohout