Click here to Skip to main content
Click here to Skip to main content

LiteZip and LiteUnzip

By , 7 Aug 2008
 

LiteZip/LiteUnzip

LiteZip.dll and LiteUnzip.dll are two Win32 Dynamic Link libraries. The former has functions to create a ZIP archive (i.e., compress numerous files into a ZIP file). The latter has functions to extract the contents of a ZIP archive.

This project is largely based upon work by Lucian Wischik, who in turn based his work on gzip 1.1.4, zlib, and info-zip which are by Jean-Loup Gailly and Mark Adler. Lucian's code has been reworked to be written in plain C, using only the Win32 API, and packaged into 2 DLLs. (Also some improvements to error-checking, some added functionality, and code-reduction/stream-lining was accomplished.)

The primary benefits of these 2 DLLs are as follows:

  • You can unzip (extract the contents) from a zip archive that's in a diskfile, memory-buffer, or pipe. And, you can unzip those contents into a diskfile, memory-buffer, pipe, or even a combination of the preceding.

    The same applies to creating a zip archive. You can create the zip archive on disk, in memory, or to a pipe. And, the contents of this zip archive can come from diskfiles, memory-buffers, pipes, or even a combination of any/all of the preceding.

    Given this flexibility, you're not required to write out your files to a temporary directory before using them. One noteworthy feature is that you can unzip directly from an embedded resource into a memory buffer or into a diskfile, which is great for installers. Another useful feature is the ability to create your zip in dynamically growable memory backed by the system pagefile (i.e., you don't need to guess the allocation size of a memory buffer before zipping some stuff into that memory buffer. You can let the DLL grow the memory buffer on-the-fly, as needed, on your behalf).

  • The zip and unzip functions are each in their own DLLs. So for example, if you need only to extract files from a ZIP archive, but not create ZIP archives, then you can use only LiteUnzip.dll and do not need to waste resources for code that you don't need (in LiteZip.dll).
  • The DLLs can be used by any program written in any language (that can load and call a standard DLL). This includes C or C++ compiled code, Visual Basic, etc. Although the source code for the DLLs is written in plain C, the compiled DLLs are included for those people who just want to use the DLLs with any language. A text file (Vb.txt) is supplied with function definitions to use the DLLs from Visual Basic.

    And an update to the DLL means that all programs using it automatically obtain the update without needing to be recompiled.

  • The DLLs themselves have a small footprint. For example, LiteZip.dll is only around 40K. One copy of a DLL's code can be shared among many running programs. Read-only data in the DLL is also shared (i.e., some of the large "lookup tables"). On systems with limited memory, this can be a valuable feature.
  • The DLLs support password-based zip encryption.
  • The one set of DLLs support both Unicode and ANSI strings. You don't need separate DLLs for Unicode versus ANSI, nor do you need to recompile the DLLs.
  • The DLLs should work under all versions of Windows, including CE.
  • All human readable strings are in each DLL's resources, facilitating the easy creation of non-English language versions of these DLLs.
  • The DLLs also support reading and writing GZIP format (single file only -- not a tar ball).

The limitation of these DLLs is:

  • They don't support disk-spanning

Using the Code in a C/C++ Program

To allow your C/C++ code to create a zip archive, add the file litezip.lib to your project, and #include "LiteZip.h" to your source code.

To allow your C/C++ code to unzip an archive, add the file liteunzip.lib to the project and #include "LiteUnzip.h" to your source code.

Zip and unzip can co-exist happily in a single application. Or, you can use only the one you need if you're trying to reduce size.

Of course, you must distribute LiteZip.dll and/or LiteUnzip.dll with your application.

The following code snippets show how to use zip/unzip. They use ANSI, but #define'ing UNICODE will use the Unicode version of the functions instead. Error checking has been omitted for brevity.

Example 1 - Create a zipfile (on disk) from Existing Files

To take some existing files on disk, and create a zip archive on disk, do the following:

  1. Call ZipCreateFile. You pass a handle to where you wish ZipCreateFile to supply an HZIP to you. You do not need to know the particulars of this handle. You'll simply pass it to other functions in LiteZip.dll just like you may pass a CreateFile() handle to ReadFile(). You also pass the filename for the zip archive you would like to create on disk. The name can include the full path such as "C:\My Directory\MyArchive.zip". If you wish to use encryption, you also pass the password string. If not using encryption, pass a 0 instead.

    If successful, ZipCreateFile will create an (empty) zip archive on disk, and fill in your HZIP handle.

  2. Call ZipAddFile for each file you wish to add to the zip archive. You'll pass the HZIP handle supplied to you by ZipCreateFile, the filename of the file to be added to the archive, and the name you wish it to have inside of the zip archive. (You may wish to trim off some of the directories on the latter name if you want a relative directory hierarchy in the zip. Or you may wish to prepend directory names to create some directory hierarchy within the zip archive.)
  3. After you're done adding items to the zip archive, call ZipClose to finish up. You'll pass the HZIP handle supplied to you by ZipCreateFile.

Here's an example of the above. Assume that we have two files on disk, named "simple.bmp" and "simple.txt". We wish to zip them up into a zip archive named "simple1.zip".

#include <Windows.h>
#include "LiteZip.h"

HZIP hz;

ZipCreateFile(&hz, "simple1.zip", 0);
ZipAddFile(hz, "simple.bmp");
ZipAddFile(hz, "simple.txt");
ZipClose(hz);

The downloaded example zip file contains a similar example, with error-checking, and also dynamic linking to LiteZip.dll. (With dynamic linking, you don't add LiteZip.lib to your project. And LiteZip.dll is not loaded when your app first starts. It is loaded only when you call LoadLibrary).

Example 2 - Unzip a zipfile (on disk) to Files on Disk

To take a zip archive on disk, and unzip its contents to disk, do the following:

  1. Call UnzipOpenFile. You pass a handle to where you wish UnzipOpenFile to supply an HUNZIP to you. You do not need to know the particulars of this handle. You'll simply pass it to other functions in LiteUnzip.dll. You also pass the filename for the zip archive you would like to unzip. The name can include the full path. If the zip is encrypted. you also pass the needed password string. If not using encryption, pass a 0 instead.

    If successful, UnzipOpenFile will open the zip archive on disk, and fill in your HUNZIP handle.

  2. Call UnzipGetItem to determine how many items (files) are in the zip archive. You supply a ZIPENTRY struct to UnzipGetItem. (This is defined in LiteUnzip.h). You can allocate this struct using a memory function such as malloc, or declare it on the stack, or declare it as a global variable, etc. (If you allocate it, you're responsible for freeing it). Set the ZIPENTRY's Index field to -1 before you pass it to UnzipGetItem. You'll also pass the HUNZIP handle supplied to you by UnzipOpenFile.

    UnzipGetItem will set the ZIPENTRY's Index field to how many items are inside the zip archive.

  3. Loop around calls to UnzipGetItem and UnzipItemToFile to extract each item from the archive, and save it on disk.

    To extract an item, you first set the ZIPENTRY's Index field to which item you wish to extract (where 0 is the first item, 1 is the second item, 2 is the third item, etc.).

    Pass your ZIPENTRY, and the HUNZIP handle supplied by UnzipOpenFile, to UnzipGetItem. UnzipGetItem will fill in the ZIPENTRY with information about that item. This includes its name, its uncompressed size, its modification date, etc. If you want to extract only a particular item, rather than calling UnzipGetItem, you can fill in your ZIPENTRY's Name field with the desired item's name, and pass your ZIPENTRY to UnzipFindItem to fill in your ZIPENTRY with other information about that item.

    Finally, call UnzipItemToFile to extract that item to a disk file. Pass your ZIPENTRY, the HUNZIP handle supplied by UnzipOpenFile, and the filename you wish the item to be saved to. (You can use the ZIPENTRY's Name field if you want to use the same name it had within the archive). UnzipItemToFile will extract the item and save it to disk, creating any needed directories.

  4. After you're done extracting items from the zip archive, call UnzipClose to finish up. You'll pass the HUNZIP handle supplied to you by ZipOpenFile.

Here's an example of the above. Assume that we have a zip archive on disk named "simple1.zip". We'll extract all its items, using the same filenames as within the archive. No encryption is used.

#include <Windows.h>
#include "LiteUnzip.h"

HUNZIP   huz;
ZIPENTRY ze;
DWORD    numitems;

ZipOpenFile(&huz, "simple1.zip", 0);

ze.Index = (DWORD)-1;
UnzipGetItem(huz, &ze);
numitems = ze.Index;

for (ze.Index = >0; ze.Index < numitems; ze.Index++)
{
   UnzipGetItem(huz, &ze);
   UnzipItemToFile(huz, ze.Name, &ze);
}

UnzipClose(huz);

The downloaded example UnzipFile contains a similar example, with error-checking, and also dynamic linking to LiteUnzip.dll. (With dynamic linking, you don't add LiteUnzip.lib to your project. And LiteUnzip.dll is not loaded when your app first starts. It is loaded only when you call LoadLibrary).

Here's an example of extracting only the item named "readme.txt" from the same zip archive:

HUNZIP   huz;
ZIPENTRY ze;

ZipOpenFile(&huz, "simple1.zip", 0);
lstrcpy(ze.name, "readme.txt");
UnzipFindItem(huz, &ze, 0); // Pass a 1 for case-insensitive find
UnzipItemToFile(huz, ze.Name, &ze);
UnzipClose(huz);

Example 3- Unzip from Resource Directly into Memory

This technique is useful for small games, where you want to keep all data files bundled up inside the executable, but reduce their size by zipping them first. It may also be useful for an installer, where the files to be installed are zipped into an archive that is embedded in the installer EXE's resource.

Assume our project has a .RC file with the line

1 RCDATA "file.zip"

to embed the zipfile as a resource. Let's also assume that this zip archive contains an item named "sample.jpg", and we wish to unzip that one item into a memory buffer.

The technique is very similar to the above unzip example, except:

  1. We call UnzipOpenBuffer instead of UnzipOpenFile. After all, the zip archive is not a separate zip file on disk. Rather, it is part of our EXE's resources. The third arg is the resource id number. We used the number 1 in our RCDATA statement above.
  2. We call UnzipItemToBuffer instead of UnzipItemToFile. After all, we want to unzip the item to a memory buffer we create, rather than a file on disk. Note that UnzipFindItem fills in the ZIPENTRY's UncompressedSize field with the size of the buffer we'll need. So we allocate that with GlobalAlloc (or in C++, you can use new).
  HUNZIP   huz;
  ZIPENTRY ze;
  char     *buffer;

  UnzipOpenBuffer(&huz, 0, 1, 0)

  lstrcpy(ze.name, "sample.jpg");
  UnzipFindItem(huz, &ze, 0);

  buffer = (char *)GlobalAlloc(GMEM_FIXED, ze.UncompressedSize);

  UnzipItemToBuffer(huz, buffer, ze.UncompressedSize, &ze)

  UnzipClose(huz);
  
  // Here you would do something with the contents of buffer.

  GlobalFree(buffer);

The downloaded example UnzipResource shows how an installer EXE may unzip the entire contents of an archive embedded in its resources.

Other Examples

You can also zip up some existing file into an archive that is created in a memory buffer. You can either supply your own memory buffer (and make sure it's big enough to accommodate the resulting archive), or you can simply let LiteZip.dll allocate the buffer from system paged memory. In the latter case, the DLL can automatically grow the buffer on-the-fly as needed.

Furthermore, you can add the contents of some memory buffer.

The downloaded example ZipMemory shows the zipping the contents of a memory buffers into an archive created in memory. The example lets the DLL allocate system paged memory for the resulting archive. It's similar to the zip example above except:

  1. We call zipCreateBuffer instead of ZipCreateFile. After all, the zip archive is not going to be created on disk. Rather, it is going to be created in memory. The third arg is the maximum limit to the growable size. You can make this a very large number because memory will be only reserved, but not actually committed, until needed.
  2. We call ZipAddBuffer instead of ZipAddFile. After all, we want to zip up a memory buffer's contents rather than some existing file on disk.
  3. Because we let the DLL allocate growable memory, rather than supplying our own buffer, we have to call ZipGetMemory to retrieve the buffer that the DLL creates the zip archive in. We don't need to call ZipClose because ZipGetMemory does that for us. We're also responsible for freeing that memory.

Sometimes, you may need to zip up some data with the resulting archive not having a ZIP header, nor ZIP "central directory" in it. I'll refer to this as a "raw" zip. For example, this is the case with a compressed ID3 tag. For this purpose, LiteZip offers a few functions to add data to a raw archive: ZipAddFileRaw, ZipAddHandleRaw, ZipAddPipeRaw, and ZipAddBufferRaw. Only one item can be added to such an archive. To later unzip the data item from this archive, you will need to use one of LiteUnzip's functions to open a raw archive: UnzipOpenFileRaw, UnzipOpenBufferRaw, or nzipOpenHandleRaw. You can then unzip the one item by calling UnzipGetItem, but first you will have to know both the compressed size of the archive, and also the size of the item when it is compressed. You stuff these two values in the ZIPENTRY's CompressedSize and UncompressedSize fields, respectively, before you call UnzipGetItem. The example ZipMemoryRaw shows how to create a raw archive. And the example UnzipMemRaw shows how to extract the one item from that same raw archive.

Updates

  • March 11, 2006: Added the function ZipAddDir() to LiteZip.dll to easily zip up the contents of a directory (including the contents of its sub-directories). Also included a new C example, ZipDir, to demonstrate this.
    NOTE: ZipAddDir does not add empty sub-directories to the zip archive.
  • August 8, 2008: Added support for "raw" archives.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

About the Author

Jeff Glatt
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
BugZipAddDirW not workingmemberdv201224 Jun '12 - 2:17 
I'm surprised nobody reported that ZippAddDirW (unicode version) doesn't work.
Even the ZipDir.c example doesn't work : it only creates an empty zip file. I'm using Windows 7.
 
Also replace_slashesW should not cast wchar_t to short and then compare short to char...
QuestionVery goodmemberlewix19 Apr '12 - 5:13 
Usefull and REALLY portable library, just updated for a C development on pos ingenico Smile | :)
Thank you!
GeneralMy vote of 5memberMember 752503117 Aug '11 - 22:01 
Thank You Supply This Code,Thank You
China HappyTrace!
QuestionCannot extract a single filed archivememberRich Nowak31 May '11 - 11:49 
The code works for multiple filed zip files.
 
Has anyone successfully extracted anything from a zip file which contained only one compressed file?
 
Thanks,
Rich
QuestionCompress Levelmembercyclonpark8 Oct '10 - 18:39 
I think... Your Zip Source Support Level between 1 to 8. but I need Level 0.
 

 
So, i tried edit your source in zip.cpp.
 

 
ZRESULT TZip::ideflate(TZipFileInfo *zfi)
 
{
 
state->param=this; state->level=8; state->seekable=iseekable; state->err=NULL;
 
}
 

 
Level 8 is max level. I tried to change level from 8 to 0.
 
but not working.
 

 
i want to just store to zip file. not compress.
 

 
Please Help Me.
QuestionIs it possible to store a text comment inside archive?memberYumashin Alex1 Oct '10 - 7:35 
Is it possible to store a text comment inside archive?
Generalsample is wrongmemberDiabloMT27 Jun '10 - 22:53 
Sleepy | :zzz: the sample is wrong!!
 
wrong:
ZipAddFile(hz, "simple.bmp");
ZipAddFile(hz, "simple.txt");
 
OK:
ZipAddFile(hz, "file name", "file path");
ZipAddFile(hz, "file name", "file path");
GeneralBUG :losing data while unzip files which are larger than 16384 and encrypted with a password.membershunruo2 Dec '09 - 15:54 
line 3904 in {liteunzip.c} "readEntry": tunzip-> EntryReadVars.RemainingUncompressed -= uDoEncHead;
what's the purpose to use this line?Confused | :confused:
I removed it,and the procedure works well. Roll eyes | :rolleyes:
GeneralLooks good, but does can it unzip a block of memorymemberMember 428011711 Aug '09 - 5:12 
Hi there,
 
I have a requirement thus here..
 
I already have a file in memory, so do not want to load it in again. The file was encrypted, so the decrypted ZIP is already in memory, and i dont wish it to reside on the hard drive.
 
Is this possible with LiteUnzip, therefore no files involved. If so, which functions in the API do i use?
 
Cheers
GeneralBUG: UnzipGetItemW Get Chinese FileName ErrormemberMember 40453813 Jun '09 - 23:49 
BUG: UnzipGetItemW Get Chinese FileName Error
 
if a zip file include a file of filename is chinese
use UnzipGetItemW will get a BAD file name.
GeneralRe: BUG: UnzipGetItemW Get Chinese FileName Errormemberyiruirui2 Aug '12 - 15:56 
exactly
so,I changed other method----zlib.
zlib is OK. Blush | :O But thanks the author all the same.
GeneralThank youmemberWeiHua zhang11 Apr '09 - 22:16 
LiteZip has many bugs , but it is very eary for using ! thank you jeff!
Generalbug !You cannot add a .zip file to you archive when zipping.it's crc will be wrong! it's size is zero!memberggbuilder.l8 Apr '09 - 4:01 
fatal.
QuestionI can't find 'ZipAddDir' function in LiteZip.h file.memberredsusia_KR24 Mar '09 - 15:32 
I can't find ZipAddDir Function in LiteZip.h file.
 
So I can't compress some folders.
 
my development environment is visual Studio 2008.
and i'm developing MFC Application.
AnswerRe: I can't find 'ZipAddDir' function in LiteZip.h file.memberggbuilder.l6 Apr '09 - 21:37 
yes,I can only find a 'ZipAddFolder' in it.So we can make it ourselves!
QuestionZR_PASSWORD not returnedmember0xFF3 Feb '09 - 0:39 
Hi,
 
first of all great work! Very easy to use.
 
But if i am using UnzipOpenFile() to open an password protected zip with a wrong password it does not return ZR_PASSWORD, instead it returns ZR_OK. Than I can extract the files but they're empty.
 
I think this is a bug?
 
Greetings,
0xFF
QuestionQuestion about DIRSLASH_CHAR -- unable to compile .dlls without changing preprocessor switchesmemberjasonharrison7 Jan '09 - 8:04 
At the top of LiteUnzip.c is a set of preprocessor switches for WIN32 vs Linux, and the WIN32 section includes a test for CP_UTF8. I'm using Visual Studio 2008 SP1 on WinXP SP3 and I'm finding that WIN32 is defined and so is CP_UTF8, this means that DIRSLASH_CHAR is not defined, which fails the compilation. Here is the code indented for readability:
 

#ifdef WIN32
...
#ifndef CP_UTF8
#define CP_UTF8 65001
#define DIRSLASH_CHAR
#endif
#else
...

 
Question: Why is the definition of DIRSLASH_CHAR nested within the CP_UTF8 test?
 
Question: Did the state of CP_UTF8 being defined/not defined change? All three settings of "Character Set" in Visual Studio ("Not Set", "Use Unicode Character Set", "Use Multi-Byte Character Set") have CP_UTF8 defined, to the value of 65001.
 
-Jason
QuestionRunning UnzipFile on LiteZip.zip produces an error when creating an "empty" directorymemberjasonharrison7 Jan '09 - 7:23 
As a test of LiteZip I tried running UnzipFile on the file LiteZip.zip renamed to test.zip (therefore no changes were needed to be added to the code).
 
Unfortunately UnzipFile fails when it tries to unzip:
C:\Documents and Settings\harrison\Desktop\LiteZip\UnzipFile\Debug\ZipDir\MyDir\
 
as it "Can't create/open file"
 
Has anyone else come across this problem? (I don't see any reports on it.)
 
I'll take a closer look at this problem but thought you all should know. This is the 40th entry in the zipfile, and all previous entries in the LiteZip.zip file are files, not directories.
 
-Jason
AnswerRe: Running UnzipFile on LiteZip.zip produces an error when creating an "empty" directorymemberjlenz27 Jan '10 - 13:08 
Did you get this resolved?
GeneralRe: Running UnzipFile on LiteZip.zip produces an error when creating an "empty" directorymemberjasonharrison27 Jan '10 - 17:50 
I do not recall if I did. Unfortunately it was at a previous employer so any changes to the source that I might have made are no longer available to me.
GeneralZipAddDirmemberksumm23 Dec '08 - 0:49 
I have used the ZipAddDir function to create my zip, which seems to create the zip but when I try to open the archive I get the following error message from windows: "Windows cannot open the folder. The Compressed (zipped) Folder 'C:\Temp\Dump\MyTest.zip' is invalid.
I followed the exmaple you provided with the source, I wonder if you could tell me where I am going wrong.
Here is my source:
 
ZipCreateFilePtr *lpZipCreateFile;
ZipAddDirPtr *lpZipAddDir;
ZipClosePtr *lpZipClose;
ZipFormatMessagePtr *lpZipFormatMessage;
 
//get the zip dll
zipDll = LoadLibrary("LiteZip.dll");
if (zipDll !=NULL)
{
// Get the addresses of 4 functions in LiteZip.dll -- ZipCreateFile(), ZipAddDir()
// ZipClose(), and ZipFormatMessage.
lpZipCreateFile = (ZipCreateFilePtr *)GetProcAddress(zipDll, ZIPCREATEFILENAME);
lpZipAddDir = (ZipAddDirPtr *)GetProcAddress(zipDll, ZIPADDFOLDERNAME);
lpZipClose = (ZipClosePtr *)GetProcAddress(zipDll, ZIPCLOSENAME);
lpZipFormatMessage = (ZipFormatMessagePtr *)GetProcAddress(zipDll, ZIPFORMATMESSAGENAME);
 
TCHAR buffer[MAX_PATH];
TCHAR buffer2[MAX_PATH];
 
CString strZipPath("C:\\Temp\\Dump");
SetCurrentDirectory(strZipPath);
result = GetCurrentDirectory(MAX_PATH, buffer);
 
if (!(result = lpZipCreateFile(&hz, _T("MyTest.zip"), 0 )))
{

strZipPath = "C:\\Temp\\Dump\\MiscFiles";
SetCurrentDirectory(strZipPath);

result = GetCurrentDirectory(MAX_PATH, buffer2);
 
if((result = lpZipAddDir(hz, &buffer2[0], result+1)))
{
lpZipClose(hz);
AfxMessageBox("Directory zip failed");
}
 
}
}
 
I'd appreciate any help you could give.
 
Keith
GeneralRe: ZipAddDirmemberksumm23 Dec '08 - 21:06 
Realized what I had done wrong, forgot to close the archive doh!
GeneralCorrupted timesmemberSébastien Foutrier15 Dec '08 - 0:13 
In the function dosdatetime2filetime there is a bug for the seconds.
*dostime |= (WORD)((st.wSecond*2)&0x1f);
should be
*dostime |= (WORD)((st.wSecond/2)&0x1f);
 
Without this change, I have sometime bugs when reading generated zip file. (with the liteUnzip or winrar)
Generalunicode!!memberhyji23 Nov '08 - 4:42 
LiteUnzip don't support in unicode...
QuestionCompile Unix-style library (*.a) from LiteZip/LiteUnzip?memberAndreas Eibach12 Nov '08 - 11:04 
Well, I've seen a *.lib is there, however, it will only produce *.so files which to my knowledge are Linux (and derivatives) only; only Cygwin works with .so files, but afaik MinGW doesn't.
Has anyone built a liblite.a or some sort? Smile | :)
This will probably make it easier to compile the library into MinGW projects. Zip-Utils does what I need, however, it's C++ but I'm coding ANSI-C.
 
------------
Andreas

GeneralUnzipToMemRaw does not work here [modified]memberAndreas Eibach12 Nov '08 - 10:58 
This is awesome work, thank you!
Been looking for some time to get the zlib code persuaded to unzip to a _memory buffer_ instead of a file!
All my attempts resulted in some data, but arbitrarily put into location! (i. e. the 1767. byte was at location 258 etc., probably due to the original code only reading 8K chunks - contrib/miniunz.c, line 372)
 
OK, tested it:
UnzipToMemRaw did NOT work when compiled with MinGW/GCC. In the language of the Windows locale, it says "The specified module was not found".
It cannot be a missing DLL because I have it in both the UnzipToMemRaw/ directory and the root directory of the package.
 
[EDIT]
 
Found it out myself!
 
It's a bug in the code, which should be fixed.
The debug code was left in, and so is the directory! Smile
 
[unziptomemraw.c:49]
if ((unzipDll = (HMODULE)LoadLibrary(_T("../LiteUnzip/Debug/LiteUnzip.dll"))))
 
must be
 
if ((unzipDll = (HMODULE)LoadLibrary(_T("../LiteUnzip.dll"))))
 
and all of a sudden it works!
Generalthank youmemberWeiHua zhang22 Oct '08 - 22:55 
your zip project is much eary for user, but more bugs is posted on codeproject.
Thank you.
QuestionABORTED?memberEdin_el_Bosnewi4 Oct '08 - 12:21 
Hi,
 
Great job.... but I have one problem. I am using your \ZipFile example and when I zip files it I get Error Message: Aborted. The file iz zipped correctly though. What could be the problem???
 

Thanks,
DIno
QuestionUnzipOpenBuffer problem?memberBoilingolf23 Sep '08 - 18:00 
I have some problem in using UnzipOpenBuffer()interface,my routine is as follows:
 
use ZipCreateBuffer() to create zipbuffer,
use ZipAddBufferA() to add string to zipbuffer through HZIP;
use ZipGetMemory() to get archived data memeory address (TZIP distination member)and data length;
 
all the above is ok;
 
But when i use the archived memory address got by ZipGetMemory()interface in UnzipOpenBuffer(), the retcode is 6,means corrupt data; I dont know why? Anyone has the same problem or anyone would help me?
 
retCode = ZipGetMemory(huz,(void **)&AfterCompressedBuffer,&AfterCompressed,(HANDLE *)&xp);
 
retCode = UnzipOpenBuffer(&hunzip,AfterCompressedBuffer,AfterCompressed,0);
GeneralSet password will lost 12 bytesmemberWeiHua zhang9 Sep '08 - 2:13 
1. the bug is belong in unzip.
2. the size of origin file must bigger than 16348.
3. unzip will lead failed!
4. line 3094 //tunzip->EntryReadVars.RemainingUncompressed -= uDoEncHead; ----> error
GeneralHI jeff~~memberMember #156552011 Aug '08 - 16:49 
Laugh | :laugh:
HOw are you jeff?
 
-천재원주-

GeneralBug when using a passwordmemberSteve Johnson (Sven)26 Jun '08 - 6:29 
I found a bug that causes a file to be unzipped minus the last n bytes, where n = the length of your password + 1. In my case, the file being unzipped was itself a zip file.
 
I commented out this line ( unzip.cpp, line 3517 ):
 
//pfile_in_zip_read_info->rest_read_uncompressed-=uDoEncHead;
 
and it now works properly.
GeneralRe: Bug when using a passwordmemberSteve Johnson (Sven)26 Jun '08 - 6:36 
It appears not to be the password length, but the length of the encryption header. By coincidence my password length was 11
GeneralRe: Bug when using a passwordmemberSteve Johnson (Sven)26 Jun '08 - 6:43 
Sorry, posted to wrong site - the bug is in the code this project was derived from.....
GeneralZIPENTRYINFOmembersachin_chakote2 Jun '08 - 4:43 
in liteunZip.c
struct ZIPENTRYINFO holds
unsigned long dosDate; // last mod file date in Dos fmt 4 bytes
 
Why only last modification date ?
Why not Last Access or creation time.
 
Is this reason why we do not get creation and last accesstime of unzipped file which is zipped with LiteZip.
 

Thanking in anticipation
 
sachin
Generaldatetime preservationmembersachin_chakote2 Jun '08 - 0:40 
Can the program preserve date timestamps when zip and unzip using LiteZip ..
 
e.g. if i used litezip and compress a file and use liteunzip to decompress will it preserve original creation, modification, access dates ?
 

thanks
sachin
GeneralQuery Regarding ZipAddDir()memberjohnarg26 May '08 - 22:10 
Thank you for posting such a nice work. I want to use the function ZipAddDir() which has its header as given below:
//////////////////////////////////////////////////////
#define ZipAddDir ZipAddDirW
DWORD WINAPI ZipAddDirW(HZIP, const WCHAR *, DWORD);
 
I want to know about third argument which is offset value. I found that if I use offset value -1 then it is working properly. What is the correct value ?
 
Could you please explain? Also, any help to use Progress Bar during zipping ?
 
Thanking you in advance.
 
Regards,
Johnarg
 
Johnarg
GeneralRe: Query Regarding ZipAddDir()memberMember 446483228 Aug '08 - 6:44 
Yes. ZipDir demo source code shows ZipAddDir should be used in this way:
result = strlen(&buffer[0]);
ZipAddDir(hz, &buffer[0], result + 1);
The offset can be used to control relative path in Zip file. Aobe code keep the original whole path.
GeneralMy adds for delete/add [modified]memberBrian Poe22 May '08 - 10:51 
I modded LiteZip.c/.h to support deletes and adds to an existing zipfile without having to decompress & recompress. If the author is interested, let me know.
 
modified on Saturday, June 7, 2008 5:19 PM

GeneralRe: My adds for delete/addmemberwoodfish794 Nov '08 - 3:25 
Hi,
 
I am interested in your changes. Can you please forward them to my email via fuqian@gmail.com? Thanks.
 
Best,
Fu Qian
QuestionBuild Error using example codememberWayne Munslow30 Apr '08 - 23:54 
When I try to add a file, using the example code:
 
ZipAddFile(hz, "simple.bmp");
 
I get a build error:
 
error C2660: 'ZipAddFileA' : function does not take 2 parameters
 
which is consistent with the declaration in LiteZip.h
 
DWORD WINAPI ZipCreateFileA(HZIP *, const char *, const char *);
 
Am I missing something obvious here?
 
Thanks to whoever can help..
Questioncan not add compress file(zip/rar) into created zip file?memberjacky_zz30 Apr '08 - 0:10 
when i add local compress(zip/rar) file into created zip file, no error occurred, but open this created zip file with WinRar, an error message displayed that created zip file is broken, why?? and i add other type file to this created zip file, open it with WinRar, no error. can not add compress file(zip/rar) into created zip file?
 
jacky_zz
2008-4-30
GeneralLitezip probable Bugmemberjhpoussy24 Apr '08 - 21:03 
Litezip/Liteunzip is great packaging aroung JL. Gailly's original code (that widely available), especially fast/samll foorptint compared to other wrappers around.
However, I VERY STRONGLY SUSPECT a quite major difficulty, that is:
LiteZip compressing algorithm is hopelessly confused with files that are already in compressed (ie. PKZIP) format: whenever you request LiteZip to make an archive from a mix of "regular" and compressed (such as Windows .zip and/or Linux .gz files), the resulting archive cannot be retrieved by other unzipping programs: the zipped files contents seem to be compressed to ZERO size, with a zero CRC value); that' s, at least, what industry ZIP programs report (Winzip 9 ...).
 
I am afraid I don't have the time to go down tracing the code to see what' s going wrong, I might suggest that Litezip should discover that source file is already compressed (just by detecting the various "PKxx" record markers), copy file to output stream without any attempt to compress any further, while marking file's header as uncompressed, not deflated; does it make sense ?
 
Besides this, a very good piece of work.
Jean-Henri

GeneralRe: Litezip probable Bugmemberwoodfish794 Nov '08 - 17:19 
I just figured out that the problem is because a bug inside the code.
 
The library will just "STORE" the already compressed file into the package. Inside the istore function, you need put "tzip->csize += cin;" inside the while loop too, which is only put outside the loop right now. That is why it always gets 0 size.
GeneralPaths in ZIP filememberS. Jaisimha3 Apr '08 - 23:17 
First of all, thanks for the excellent library.
 
Is there any way to avoid storing the path in the ZIP file? For ex, if the zip is "C:\Somewhere\Sample.zip" and I add two files to it, "C:\Another Place\First.doc" and "C:\One more place\Second.doc", the archive stores the paths within the zip archive. Is there a flag or setting to avoid that and not store a path, i.e., the un-zip (using say WinZip) will just unzip to selected folder. I know there is a flag within WinZip to ignore the file paths, but I wanted to know if it can be done while zipping.
GeneralLicensing QuestionmemberCodeProjectIsCool3 Jan '08 - 0:26 
Is it allowed to use your Code in a commercial application if yes how are the licensing details?
AnswerRe: Licensing QuestionmemberJeff Glatt14 Jan '08 - 8:02 
The licensing details are the same as the code it is based upon, zlib at http://www.gzip.org/zlib by Jean-Loup Gailly and Mark Adler.
GeneralRetrieving the CRC valuesmembercschmidt6 Nov '07 - 6:58 
Hi Jeff,
 
Great article and equally great work.   What I was trying to find out is how one could get the CRC values for the zip archive file and each file individually.   I really actually only need the CRC of the archive file itself.   It appears the code is in place but this information is not exposed or maybe I'm just missing it.   We store the CRC value in a database along with the archive file itself so I'll need to get this value prior to incorporating you efforts into my small program.
 
Thanks again Jeff or to whomever replies to this message.
 
Craig
GeneralAppreciate your effortsmemberlancelaneway11 Nov '07 - 17:32 
Been looking for a mature and flexible compression solution. Standard C is the way to go to reduce bloat, increase flexibility, and ease porting code. While I have noticed readers commenting on specific bugs and issues, I think LiteZip is a candidate for further development.
 
However, I would prefer a static library, instead of a dynamic one, so that will be my primary focus delving into it...
 
Thank you for your efforts, they are much appreciated.
 

GeneralUnzip doesn't unzip all the filememberagambier_ae18 Sep '07 - 6:31 
Hello,
 
thanks for this library.
 
I have a little problem when i unzip a file with liteunzip.
 
Some files (a lot) are not complete, some bytes are missing.
 
I tried to unzip the file with izarc and everything is ok.
So the archive file is correct and maybe there is a bug in the function.
Can you help me ?
 
Thanks very much.
Alexandre GAMBIER
 
here my code :
 
// Ouvre le fichier zip
if( UnzipOpenFile( &hZIP, szZIPFile, GLB_ZIPPASSWORD )!=ZR_OK )
return( FALSE );;
 
// Définit le répertoire de sortie
if( UnzipSetBaseDir( hZIP, szDstDir )!=ZR_OK )
{
UnzipClose( hZIP );
return( FALSE );
}
 
// Extrait tous les fichiers
memset( &tZipEntry, 0, sizeof( tZipEntry ) );
 
// Combien de fichier ?
tZipEntry.Index = -1;
if( UnzipGetItem( hZIP, &tZipEntry )!=ZR_OK )
{ UnzipClose( hZIP );
return( FALSE );;
}
dwEntryCount = tZipEntry.Index;
 
// Extrait les fichier un par un
wErr = FALSE;
for( tZipEntry.Index = 0; tZipEntry.IndexAdd( tZipEntry.Name );
}
}
 
// ferme le zip
UnzipClose( hZIP );
 
if( wErr!=FALSE ) return( FALSE );
 
return( TRUE );

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 8 Aug 2008
Article Copyright 2006 by Jeff Glatt
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid