How to unzip a big zip file containing one file and get the progress in bytes with swift?

前端 未结 4 2030
无人共我
无人共我 2020-12-30 03:35

I try to unzip a big zip file containing only one item (more than 100MB) and like to show the progress during unzipping.

I found solutions where the progress can be

4条回答
  •  清酒与你
    2020-12-30 04:01

    To achieve what you want, you will have to modify SSZipArchive's internal code.

    SSZipArchive uses minizip to provide the zipping functionality. You can see the minizip unzipping API here: unzip.h.

    In SSZipArchive.m, you can get the uncompressed size of the file being unzipped from the fileInfo variable.

    You can see that the unzipped contents are being read here:

     FILE *fp = fopen((const char*)[fullPath UTF8String], "wb");
     while (fp) {
         int readBytes = unzReadCurrentFile(zip, buffer, 4096);
         if (readBytes > 0) {
             fwrite(buffer, readBytes, 1, fp );
         } else {
             break;
         }
     }
    

    You will need the readBytes and the uncompressed file size to compute the progress for a single file. You can add a new delegate to SSZipArchive to send these data back to the calling code.

提交回复
热议问题