Question

I am working on an app on Windows Phone and trying to get data from a web server by HTTP GET method, and the content-encoding field in the response indicates that the data was compressed by deflate algorithm.

I found the useful library SharpZipLib, which can deal with gzip stream with GZipInputStream, but it does not work for deflate stream.

How can I depress the stream using SharpZipLib? Or is there any other way to deal with that?

Thanks a lot!

Was it helpful?

Solution

Don't know how you can achieve this with SharpZipLib, but you do have another choice and that is DotNetZip that has a DeflateStream all packed and ready to use here!

Furthermore, AFAIK, DotNetZip is Ms-Pl licensed so it can be used in commercial applications, SharpZipLib (GPL) can't!

OTHER TIPS

Beware. An http server returning the deflate method may deliver one of two different things. Either a zlib-wrapped (RFC 1950) deflate (RFC 1951) stream (which is what the http standard specifies), or a raw deflate (RFC 1951) stream. The latter has been seen from Microsoft servers written by someone who did not carefully read the standard.

You can resolve this by trying it both ways (starting with the right way), or by not providing deflate as an accepted method from your client, only allowing gzip. There is no ambiguity with gzip.

There may be an interface to zlib to permit you to try both ways, or if not, you may need to write your own interface or use zlib directly. In zlib, you can decode a zlib-wrapped stream by starting with inflateInit(strm), or you can decode a raw deflate stream starting with inflateInit2(strm, -15).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top