English 中文(简体)
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.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签