REALLY small unzip utility for Silverlight – Part 2

I earlier blogged about a very small unzip utility for Silverlight.

However there was one problem with the method: It relied on some Silverlight framework libraries that didn’t support all zip file formats (a known bug I’m told). Some file zippers places the file size after the zip data chunk, and Silverlight does not like that. So I added a little bit to the utility to detect this case and if so, will re-arrange the bytes in the zipfile so Silverlight will read it.

So I present to you: The really small unzip utility v.2.0. It’s slightly larger than before, but still under 200 lines of code (plus comments).

It works the same way as before, so read the original blogpost to see how to use it.

Although I only tested this on Silverlight 4 and WinPhone 7, it should work with earlier Silverlight releases as well.

Download here: (2.53 kb)

Also available at NuGet

Comments (8) -

  • nicogis: slsharpziplib is fine if you want to add 200kb to your solution instead of 200 lines of code Smile
    If you want to do compression, something like this would be required though. Unzip just happens to be much simpler, because Silverlight has all the important bits.
  • I used the original 1.0 version and didn't have any problems with it. I did however modify it to support my companies custom zip headers.
  • Morten,
    Very helpful. Thanks again. One thing I miss from SharpZipLib is this method:

            public static bool IsStreamCompressed(Stream inputStream)
                bool isCompressed = false;
                using (var reader = new BinaryReader(inputStream))
                    inputStream.Seek(0, SeekOrigin.Begin);
                    if (reader.BaseStream.Position < reader.BaseStream.Length)
                        if (reader.ReadInt32() == 67324752)
                            isCompressed = true;
                        inputStream.Seek(0, SeekOrigin.Begin);
                return isCompressed;
  • This version does not have the function "GetFileNamesInZip()". Any particular reason for that?
    Or do I need to merge version 1 and 2 files ?

  • Eric: I did some refactoring. You can use the property: IEnumerable<string> FileNamesInZip { get; }
  • When I add this code file to my WPF application I get an error on line 68 saying "No overload for method 'GetResourceStream' takes 2 arguments". If I modify this line to remove the extra StreamResourceInfo, that line always throws an exception. Do I need to modify my project to make this work, somehow?
  • ionman: This code is for Silverlight. It uses API's not available in WPF.

Pingbacks and trackbacks (1)+

Add comment