Click here to Skip to main content
13,458,661 members
Click here to Skip to main content
Add your own
alternative version


36 bookmarked
Posted 9 Mar 2008

Simple zip archive unzipper

, 14 May 2008
Rate this:
Please Sign up or sign in to vote.
A very small library for unzipping zip files/streams.


If you sometimes find yourself in a situation where you need to unzip some files but really don't like the thought of having to roll out the big artillery (i.e., third-party libraries), then this simple zip archive unzipper might be the thing for you. It consists of just a single source file of about 200 lines of code, and is thus easily incorporated into your application. This way, you don't have to worry about third-party library dependencies and related deployment issues; simply compile the simple zip archive unzipper into your application, and you are ready to go.

The library supports zip-files with no compression, and zip-files compressed with the Deflate algorithm. This includes zip-files generated by the Windows Zip Shell extension (Send To -> Compressed (zipped) folder), zip-files generated by WinZip (with default compression settings at least), and zip-files generated by the Info-Zip tools.


Internally, the library only handles some simple parsing of the zip file headers. All the gory details of actually decompressing the data is left to the built-in System.IO.Compression.DeflateStream. As this class is available beginning with .NET 2.0, the library compiles and runs on the .NET 2.0, 3.0, and 3.5 platforms.

Using the code

The library contains just one class, SimpleUnZipper, with a few static methods. To unzip a file on disk to a directory on disk, simply use the UnZipTo method:

// Unzip archive to disk
SimpleUnZipper.UnZipTo(@"c:\", @"c:\foo\bar");

This will unzip the files in 'c:\' and place them in the 'c:\foo\bar' folder, creating a sub-folder structure on disk matching that of the zip-file.

The UnZipTo method also accepts a Stream as input:

// Unzip from stream to disk
using (var stream = File.OpenRead(@"c:\"))
    SimpleUnZipper.UnZipTo(stream, @"c:\foo\bar");

To get the raw decompressed data from a zip file, use the UnZip methods:

// Unzip archive manually
foreach (var file in SimpleUnZipper.UnZip(@"c:\"))
    // Do something with file.Stream here...

The UnZip methods return an IEnumerable<UncompressedFile>, where each UncompressedFile has a Name property (the file name) and a Stream property (the decompressed file data). Note that an UncompressedFile might be a directory, in which case, the Name is a directory and the Stream has a length of zero.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Anders M. Mikkelsen
Architect Vestas Control Systems A/S
Denmark Denmark
M.Sc, Computer Science, Daimi, DK

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Anuj Tripathi18-Jul-13 11:51
memberAnuj Tripathi18-Jul-13 11:51 
Questionhow can i use this class. Pin
dinhanhency26-May-09 23:59
memberdinhanhency26-May-09 23:59 
GeneralThank you! Pin
Bambi33-Jul-08 4:42
memberBambi33-Jul-08 4:42 
GeneralPasswords... Pin
Reelix11-Jun-08 23:49
memberReelix11-Jun-08 23:49 
GeneralKind of Streams Pin
ITMaiO14-May-08 3:19
memberITMaiO14-May-08 3:19 
GeneralRe: Kind of Streams Pin
ITMaiO14-May-08 4:54
memberITMaiO14-May-08 4:54 
AnswerRe: Kind of Streams Pin
Anders M. Mikkelsen14-May-08 9:44
memberAnders M. Mikkelsen14-May-08 9:44 
Well, one problem was that the unzipper was unable to operate on un-seekable streams. This is fixed now - meaning that you should be able to run something like:

<br />
  HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/");<br />
  WebResponse resp = req.GetResponse();<br />
  SimpleUnZipper.UnZipTo(resp.GetResponseStream(), "c:\\ziptest");<br />

(at least this works with my test zip files).

It should be noted that some web content is zipped on the fly (going out of the web server). These streams carry essential information in special zip file footers rather than in the headers. These kinds of streams are not supported by the simple unzipper.
QuestionCompile Error Pin
ITMaiO13-May-08 22:55
memberITMaiO13-May-08 22:55 
AnswerRe: Compile Error Pin
Anders M. Mikkelsen14-May-08 1:13
memberAnders M. Mikkelsen14-May-08 1:13 
GeneralRe: Compile Error Pin
ITMaiO14-May-08 2:08
memberITMaiO14-May-08 2:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04-2016 | 2.8.180323.1 | Last Updated 14 May 2008
Article Copyright 2008 by Anders M. Mikkelsen
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid