Question

I am trying to use static minizip library on Windows 7 64-bit, using Visual Studio 2010.
The main goal is to archive files larger 4GB.
I build zlib using CMake 2.8, and linked in to my project.
It works for files less 4GB, but doesn't work proper for files larger 4GB.
Why I have a problem with archiving 5GB file using minizip?
Did I miss something on the build libraries stage?
Here are all my steps, library and project: https://github.com/koponomarenko/file_compression

Really need help. Thanks.

Updated:

"doesn't work proper for files larger 4GB" means that my test program archives 5GB txt file without any errors during this process. I checked zipWriteInFileInZip() returns ZIP_OK for all 5,368,709,120 bytes. zipCloseFileInZip() and zipClose() don't return any errors. But in created archive (I use 7-zip) file info is:

  • Uncompressed size: 4,294,967,295
  • Compressed size: 8,806,676
  • Attributes: empty field
  • CRC: 81970625
  • Method: Deflate
  • Host OS: FAT
  • Version: 45

And I get error message "Unsupported compression method" when try to unzip (using 7-zip) this archive.

I also zipped the same 5GB txt file with 7-zip. Here is file info from this archive:

  • Uncompressed size: 5,368,709,120
  • Compressed size: 9,608,471
  • Attributes: A
  • CRC: 81970625
  • Method: Deflate
  • Host OS: FAT
  • Version: 45

The first 3 fields are different from my archive.

Updated:

void Archive::create()
{
     m_archiveHandle = zipOpen64(m_sName.c_str(), APPEND_STATUS_CREATE);

     if ( !m_archiveHandle )
     {
         throw Error("Can't create the archive. Can be already created.");
     }
}

void Archive::add(string sSrcFile, string sDstFile)
{
    //////////////////////////// create a file
    zip_fileinfo zfi;
    memset(&zfi, 0, sizeof(zfi));
    int zip64 = 1;
    int ret = zipOpenNewFileInZip64(m_archiveHandle,
        sDstFile.c_str(),
        &zfi,
        NULL, 0,
        NULL, 0,
        "my comment for this interior file",
        Z_DEFLATED,
        Z_DEFAULT_COMPRESSION,
        zip64
        );
    if ( ret != 0 )
    {
        throw Error("Can't add file to a zip archive.");
    }


    //////////////////////////// write to the file
    FILE * pFile = fopen( sSrcFile.c_str(), "rb" );
    if ( !pFile )
    {
        throw Error("Can't open target file.");
    }

    char * buf = new char[BUF_SIZE];
    int size_read = 0;
    int err;
    do
    {
        err = ZIP_OK;
        size_read = (int)fread(buf, 1, BUF_SIZE, pFile);
        if (size_read < BUF_SIZE)
            if ( feof(pFile) == 0 )
            {
                err = ZIP_ERRNO;
            }

            if (size_read > 0)
            {
                err = zipWriteInFileInZip (m_archiveHandle, buf, size_read);
            }
    } while ((err == ZIP_OK) && (size_read>0));

    delete [] buf;

    //////////////////////////// close the file
    if ( zipCloseFileInZip(m_archiveHandle) != 0 )
    {
        throw Error("Can't close added file.");
    }
}


void Archive::close()
{
    if ( !m_archiveHandle )
        return;

    if ( zipClose(m_archiveHandle, "my comment for exterior file") != 0)
    {
        throw Error( "Can't save changes and close." );
    }

    m_archiveHandle = 0;
}

I use this batch file to get static Zlib. I put it in zlib/build64 and run from "Visual Studio x64 Win64 Command Prompt".

rem ** go to the current script directory
cd %~dp0

cmake .. -G"Visual Studio 10 Win64" -DCMAKE_INSTALL_PREFIX="C:\devel\installed\zlib64"
msbuild /P:Configuration=Debug INSTALL.vcxproj
msbuild /P:Configuration=Release INSTALL.vcxproj

Updated:

Created archive can be unzipped by Total Commander and Windows Explorer. I compared a check-sum (md5, sha1) of the original file and unzipped file, and it was the same. But neither Total nor Explorer shows attributes of the compressed file. Meanwhile 7-zip says me "Unsupported compression method".

Updated December 09, 2013:

It seems that minizip has some problems with attributes when work with files larger 4GB on Windows. 7-Zip and WinZip can't unzip created archive.

Was it helpful?

Solution

The problem is in order of fields (extra field and file comment field) for Central Directory Record in ZIP. So if your file is bigger than 4GB and you added a comment for it you are going to face this bug.

It seems to me that the original author stopped maintenance this library, but I found a repo with some fresh changes on Github here https://github.com/nmoinvaz/minizip . So I wrote about this bug to the author of this repo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top