Simple ZIP Archive unzipper

Source: Internet
Author: User
Tags unzip archive
    • Download source code-1.81 KB
Introduction

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 inreceivated 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 feature des 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.

Background

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-inSystem. 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 useUnziptoMethod:

Collapse Copy code
 
//Unzip archive to diskSimpleunzipper. unzipto (@"C: \ zipfile.zip",@"C: \ Foo \ bar");

This will unzip the files in'C: \ zipfile.zipAnd place them in'C: \ Foo \ bar'Folder, creating a sub-folder structure on disk matching that of the zip-file.

TheUnziptoMethod also acceptsStreamAs input:

Collapse Copy code
//Unzip from stream to diskUsing(VAR stream = file. openread (@"C: \ zipfile.zip") {Simpleunzipper. unzipto (stream,@"C: \ Foo \ bar");}

To get the raw decompressed data from a zip file, useUnzipMethods:

Collapse Copy code
//Unzip archive manuallyForeach(Var fileInSimpleunzipper. Unzip (@"C: \ zipfile.zip") {Console. writeline (file. Name );//Do something with file. stream here...}

TheUnzipMethods returnIenumerable<Uncompressedfile>, Where eachUncompressedfileHasNameProperty (the file name) andStreamProperty (the decompressed file data). Note thatUncompressedfileMight be a directory, in which case,NameIs a directory andStreamHas a length of zero.

 

 

Reprinted: http://www.codeproject.com/KB/files/Simple_Unzipper.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.