Click here to Skip to main content
13,290,176 members (54,866 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 25 May 2009

.NET wrapper for Info-ZIP

, 25 May 2009
Rate this:
Please Sign up or sign in to vote.
A C# wrapper for the Info-ZIP library.

The challenge

Many of today's applications require the capability of extracting certain files from a ZIP archive, either onto the hard disk or into memory. A lot of useful zip libraries for .NET applications abound on the Web (SharpZipLib for .NET Framework is a very known one), but I wanted to use the Info-ZIP library as it was always my favorite library for C++ projects.

Info-ZIP is an Open Source version of Phil Katz's "deflate" and "inflate" routines used in his popular file compression program, PKZIP. Info-ZIP code has been incorporated into a number of third-party products as well, both commercial and freeware. It offers two dynamic link libraries: one for zipping, and one for unzipping.

The Info-ZIP DLLs are free to use and distribute, but they are designed to be used in C/C++ projects, so they're not really .NET-friendly. Also, the Info-ZIP package contains almost no documentation showing how to use the Info-ZIP DLLs.

Therefore, I decided to write a small C# wrapper that provides all the required data types and functions in order to give the possibility to work with the Info-ZIP API.

The solution

I built the Info-ZIP .NET wrapper as a C# library named Karna Compression where all the Info-ZIP native types and methods are hidden behind the simple .NET facade. Karna Compression library has two main classes: KarnaZip and KarnaUnzip.

KarnaZip is a class for dealing with zip archives that can add, freshen, or move files in an archive.


KarnaUnzip can be used to extract files from a ZIP archive to the hard drive or memory.


Using the code

Creation of zip archive, including password protection and comments, requires just a few lines of code:

string[] content = { "*.txt" };
KarnaZip zip = new KarnaZip();
zip.FileName = "";
zip.Password = "password"; //optional
zip.Comment = "This is my documents archive";

Other operations with a zip archive can be performed in a similar way:

//Update files

//Move files to the archive

//Delete files from the archive

Extracting files from the archive using the KarnaUnzip class is even more simple:

KarnaUnzip unzip = new KarnaUnzip("");
unzip.Password = "password"; //optional

The following code snippet shows how to extract a file from the archive to memory without saving the file to the hard drive:

byte[] rawBytes;
KarnaUnzip unzip = new KarnaUnzip("");
rawBytes = unzip.ExtractToMemory("readme.txt");

Additional information

Karna Compression is a small part of the Open Source Karna .NET library which can be downloaded from the SourceForge website:

More information about the Info-ZIP project can be found on Info-ZIP's home site:


  • 25.05.2009: Initial release.


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


About the Author

Serhiy Perevoznyk
Belgium Belgium
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionRequire c++ wrapper Pin
Aniruddha_Loya17-Sep-11 3:06
memberAniruddha_Loya17-Sep-11 3:06 
Generalinterop Pin
Donsw10-Jul-09 11:52
memberDonsw10-Jul-09 11:52 
GeneralRe: interop Pin
Serhiy Perevoznyk8-Sep-09 5:11
memberSerhiy Perevoznyk8-Sep-09 5:11 
GeneralDotNetZip Pin
Unruled Boy25-May-09 16:47
memberUnruled Boy25-May-09 16:47 
GeneralRe: DotNetZip Pin
Serhiy Perevoznyk25-May-09 22:05
memberSerhiy Perevoznyk25-May-09 22:05 
GeneralRe: DotNetZip Pin
Unruled Boy26-May-09 1:09
memberUnruled Boy26-May-09 1:09 
GeneralRe: DotNetZip Pin
Serhiy Perevoznyk26-May-09 1:28
memberSerhiy Perevoznyk26-May-09 1:28 
GeneralRe: DotNetZip Pin
Unruled Boy26-May-09 3:22
memberUnruled Boy26-May-09 3:22 
GeneralRe: DotNetZip Pin
stano2-Jun-09 7:03
memberstano2-Jun-09 7:03 
GeneralRe: DotNetZip Pin
Unruled Boy2-Jun-09 16:42
memberUnruled Boy2-Jun-09 16:42 

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 | 2.8.171207.1 | Last Updated 25 May 2009
Article Copyright 2009 by Serhiy Perevoznyk
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid