GithubHelp home page GithubHelp logo

ziparchive / ziparchive Goto Github PK

View Code? Open in Web Editor NEW
5.4K 165.0 1.3K 3.75 MB

ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS.

License: MIT License

C 73.45% Objective-C 23.52% Ruby 0.34% Swift 2.61% Rich Text Format 0.08%
unzipping-files ziparchive swift objective-c objective-c-library swift-library swift-3

ziparchive's Introduction

CI

SSZipArchive

ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS.

  • Unzip zip files;
  • Unzip password protected zip files;
  • Unzip AES encrypted zip files;
  • Create zip files;
  • Create large (> 4.3Gb) files;
  • Create password protected zip files;
  • Create AES encrypted zip files;
  • Choose compression level;
  • Zip-up NSData instances. (with a filename)

Version 2.5.0+ Updates Minimum OS Versions

A key dependency of this project is the zlib library. zlib before version 1.2.12 allows memory corruption when deflating (i.e., when compressing) if the input has many distant matches according to CVE-2018-25032.

zlib 1.2.12 is included in macOS 10.15+ (with latest security patches), iOS 15.5+, tvOS 15.4+, watchOS 8.4+. As such, these OS versions will be the new minimums as of version 2.5.0 of ZipArchive.

If you need support for previous versions of ZipArchive for earlier OS support you can target an earlier version but know you will be using an unmaintained version of this library.

We will not support versions of ZipArchive that use dependencies with known vulnerabilities.

Installation and Setup

The main release branch is configured to support Objective-C and Swift 4+.

SSZipArchive works on Xcode 12 and above, iOS 15.5 and above, tvOS 15.4 and above, macOS 10.15 and above, watchOS 8.4 and above.

CocoaPods

In your Podfile:
pod 'SSZipArchive'

You should define your minimum deployment target explicitly, like: platform :ios, '15.5'

Recommended CocoaPods version should be at least CocoaPods 1.7.5.

SPM

Add a Swift Package reference to https://github.com/ZipArchive/ZipArchive.git (SSZipArchive 2.5.0 and higher or master)

Carthage

In your Cartfile:
github "ZipArchive/ZipArchive"

We do not release a Carthage pre-built package. Developers are encouraged to build one themselves.

Manual

  1. Add the SSZipArchive and minizip folders to your project.
  2. Add the libz and libiconv libraries to your target.
  3. Add the Security framework to your target.
  4. Add the following GCC_PREPROCESSOR_DEFINITIONS: HAVE_INTTYPES_H HAVE_PKCRYPT HAVE_STDINT_H HAVE_WZAES HAVE_ZLIB ZLIB_COMPAT $(inherited).

SSZipArchive requires ARC.

Usage

Objective-C

//Import "#import <ZipArchive.h>" for SPM/Carthage, and "#import <SSZipArchive.h>" for CocoaPods.

// Create
[SSZipArchive createZipFileAtPath:zipPath withContentsOfDirectory:sampleDataPath];

// Unzip
[SSZipArchive unzipFileAtPath:zipPath toDestination:unzipPath];

Swift

//Import "import ZipArchive" for SPM/Carthage, and "import SSZipArchive" for CocoaPods.

// Create
SSZipArchive.createZipFileAtPath(zipPath, withContentsOfDirectory: sampleDataPath)

// Unzip
SSZipArchive.unzipFileAtPath(zipPath, toDestination: unzipPath)

License

SSZipArchive is protected under the MIT license and our slightly modified version of minizip-ng (formally minizip) 3.0.6 is licensed under the Zlib license.

Acknowledgments

  • Big thanks to aish for creating ZipArchive. The project that inspired SSZipArchive.
  • Thank you @soffes for the actual name of SSZipArchive.
  • Thank you @randomsequence for implementing the creation support tech.
  • Thank you @johnezang for all his amazing help along the way.
  • Thank you @nmoinvaz for minizip-ng (formally minizip), the core of ZipArchive.
  • Thank you to all the contributors.

ziparchive's People

Contributors

adamyanalunas avatar antiraum avatar boherna avatar caldofran avatar clementpadovani avatar coeur avatar davidde94 avatar dimohamdy avatar florianbachmann avatar fritzt0 avatar ibsh avatar jhudsonwa avatar jnis avatar johnezang avatar lagapollo avatar lakshmankreditbee avatar ls-philippe-casgrain avatar mollidor avatar nicked avatar nivektric avatar pietbrauer avatar randomsequence avatar rob2468 avatar screekworkshop avatar soffes avatar squaredtiki avatar ssoper avatar stuclift avatar wanewang avatar willson-chen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ziparchive's Issues

Zipping removes file modes (e.g. executable) on files

When zipping up a folder or bundle containing files which have specific file modes set such as being executable, these file modes are lost.

For example when zipping a .app file the executable in the MacOS sub directory is no longer executable and thus the app cannot be launched.

failed to open zip file

unzipping results in an error "2012-10-25 13:50:47.674 Appname[5940:c07] zip error : Error Domain=SSZipArchiveErrorDomain Code=-1 "failed to open zip file" UserInfo=0x83a4f90 {NSLocalizedDescription=failed to open zip file}"
I've added libz.dylib to my project and made sure the file I want to unzip exists.

How can this be solved?

Add writing support

Currently, you can only unzip files. The ability to zip files would be nice for completeness. I doubt many people would have a use for this though.

Buffer overflow on line 217 of SSZipArchive.m

        int bytesRead = 0;
        while((bytesRead = unzReadCurrentFile(zip, buffer, 4096)) > 0)
        {
            buffer[bytesRead] = 0;  

//* buffer OVERFLOW WHEN bytesRead == 4096, since buffer is of size 4096
//
* the valid index range for buffer is 0..4095
//**** a typical C language issue

            [destinationPath appendString:[NSString stringWithUTF8String:(const char*)buffer]];
        }

the function unzipFileAtPath doesn't extract the content of zip file

Hi,
when running the function :

BOOL success = [SSZipArchive unzipFileAtPath:filePathToUnzip toDestination:destinationPath overwrite:YES password:nil error:&errzip];

it returns YES , and no error found. but the file isn't present in the destination folder

I've tried to manually download, and unzip the file from PC, wihout problems: thus the file isn't corrupted

I think the issue is related to the "symbolic link"

has anyone experienced this issue before?

thanks
Lorena

Modification dates are wrong when creating a zip using SSZipArchive

Creating a zip on an iPad using SSZipArchive, then transferring it to a Mac and unzipping it in the OS X finder, produces files with the modification date : 30 Nov 1979 00:00.

I realise that writeFile:path doesn't fill in any date info, but shouldn't I be seeing : 31 Dec 1979 00:00 ? (i.e. 1 Jan 1980.) It looks like it's off by a month.

If I modify writeFile:path to read the file's modification date and pass this into the call to zipOpenNewFileInZip(), then when I unzip on OS X, I get dates that are 1 hour later than the original files (although I did encounter one file that retained the correct date/time).

Ie changing :

zipOpenNewFileInZip(_zip, [[path lastPathComponent] UTF8String], NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION);

to

NSError* error = nil;
NSDate* fileDate;
NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
if (error == nil && attr) {
    fileDate = (NSDate *) [attr objectForKey:NSFileModificationDate];
} else {
    fileDate = [NSDate date];
}
zip_fileinfo zipInfo = {{0,0,0,0,0,0},0,0,0};
[self zipInfo:&zipInfo setDate:fileDate];
zipOpenNewFileInZip(_zip, [[path lastPathComponent] UTF8String], &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION);

However, if I explicitly put [NSDate date] into zipInfo, I get the correct, current date (not offset by an hour).

Am I doing something wrong, or is there an underlying problem ?

tia
Lenny.

Large OSX Zip Archives (>4 GB) did not work

I have noticed, that large Zip Archives (>4 GB) which are created with OSX are not working with minizip.
I think it depends on some Meta Files which are created on the Compressing process.
Is it possible to clean the Archives before unzipping the Archives ?
It is also silly that some __MACOSX directorys are created in the Documents Directory.

problems for very large archives

I need to unpack an archive which is very large in size, both number of files and the count of files. Overall the zip is 1.8 gigs with 26,000 files in it.

Some suggestions:

  1. you need to use an @autoreleasepool {} structure in your main loop while you're yanking the individual files out of the zip. Otherwise all of the autoreleased objects that you're using will collect up on the main autorelease pool and the memory use will spiral out of control. Using this structure do { @autoreleasepool { } } while(i++ < 100000) has a much smaller memory footprint since it will nuke all of the autoreleased objects on each iteration. So I suggest you put those in.
  2. The mutable set directoriesModificationDates collects up all kinds of objects and then performs all of its actions at the end of the execution of the main loop. Again, in a mobile environment if you do this and someone encounters an archive like this (rare, but still), the set will just explode with objects causing the memory footprint to spiral way up. It is better instead to set the attributes on the fly as the objects are created, rather than collect them up into a set for processing later. This will keep your memory footprint with a known upper bound.

Both of these together implemented will mean you can process a zip archive of infinite size without ever causing the OS to nuke your process for excessive memory use. As is there are limits and SSZipArchive will get you nuked. Now, probably almost nobody will hit those limits... but I did. Might as well code it with no limits.

The side benefit is it's faster too than tracking everything in a datastructure for changing later.

Further suggestions:

Similarly this code constantly calls [self class] to get the class object to call a class method. Placing this call once at the top:

class myClass = [self class]

Will in my case save something like 100,000 method calls. Tiny mods do a lot in a mobile environment.

Oh and also for delegates, rather than check every time you send a method whether or not they implement it, its better to check once, set a flag, and use that flag to make the call.

Linker error

Undefined symbols for architecture i386:
  "_crc32", referenced from:
      _unzReadCurrentFile in unzip.o
      _zipWriteInFileInZip in zip.o
  "_deflate", referenced from:
      _zipWriteInFileInZip in zip.o
      _zipCloseFileInZipRaw64 in zip.o
  "_deflateEnd", referenced from:
      _zipCloseFileInZipRaw64 in zip.o
  "_deflateInit2_", referenced from:
      _zipOpenNewFileInZip4_64 in zip.o
  "_get_crc_table", referenced from:
      _unzOpenCurrentFile3 in unzip.o
      _zipOpenNewFileInZip4_64 in zip.o
  "_inflate", referenced from:
      _unzReadCurrentFile in unzip.o
  "_inflateEnd", referenced from:
      _unzCloseCurrentFile in unzip.o
  "_inflateInit2_", referenced from:
      _unzOpenCurrentFile3 in unzip.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

UNZ_BADZIPFILE after resumed a file download, despite file being ok.

So, I'm using AFDownloadRequestOperation to download a zip file. This works fine. But, if network connection drops, then come back on again, it refused to unzip the file giving a UNZ_BADZIPFILE. Howeever, if I manually go in and check the device tmp dire the downloaded zip file is there and I can copy it to desktop and unzip it on my Mac, so file does seem to be correct.

Any ideas?

Keep relative symbolic links relative

Currently, the library will resolve symbolic links that are relative into absolute paths, using the current working directory of the process that's doing the unzipping, which to me seems pretty wrong.

Modification Dates

Hi,
thanks you for work.
I would tell you about a problem, during unzip a very high number of files (~3000) the set directoriesModificationDates will have a big size that cause some problem and slow unzip process.
I've commented the rows where you add the modification date of every path and it has became more fast.
So you can try to set modification date at one folder for time or not set it, it's not realy useful, the creation date remain the orginal date.

Best regards,
l3nko

Undefined symbols for architecture armv7:

Hi Everyone!

I get the following 15 errors, when trying to run my project. I have added the libz.1.2.5.dylib framework, so I do not believe that is the problem.

Have anyone else had this issue, or will you be able to tell me what's wrong? I am not even calling the method, it is simply just placed in my project.

Thank you!

Error:

Ld /Users/jensnannerup/Library/Developer/Xcode/DerivedData/WebViewTutorial-gofzagbatfngzqebjbrownqfsfeq/Build/Products/Debug-iphoneos/WebViewTutorial.app/WebViewTutorial normal armv7
cd /Users/jensnannerup/Downloads/Source/WebViewTutorial
setenv IPHONEOS_DEPLOYMENT_TARGET 4.2
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -L/Users/jensnannerup/Library/Developer/Xcode/DerivedData/WebViewTutorial-gofzagbatfngzqebjbrownqfsfeq/Build/Products/Debug-iphoneos -F/Users/jensnannerup/Library/Developer/Xcode/DerivedData/WebViewTutorial-gofzagbatfngzqebjbrownqfsfeq/Build/Products/Debug-iphoneos -F/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/Developer/Library/Frameworks -filelist /Users/jensnannerup/Library/Developer/Xcode/DerivedData/WebViewTutorial-gofzagbatfngzqebjbrownqfsfeq/Build/Intermediates/WebViewTutorial.build/Debug-iphoneos/WebViewTutorial.build/Objects-normal/armv7/WebViewTutorial.LinkFileList -dead_strip -miphoneos-version-min=4.2 -framework SenTestingKit -lbz2 -lz.1.2.5 -framework QuartzCore -framework SystemConfiguration -framework Foundation -framework UIKit -o /Users/jensnannerup/Library/Developer/Xcode/DerivedData/WebViewTutorial-gofzagbatfngzqebjbrownqfsfeq/Build/Products/Debug-iphoneos/WebViewTutorial.app/WebViewTutorial

Undefined symbols for architecture armv7:
"_unzCloseCurrentFile", referenced from:
+[SSZipArchive unzipFileAtPath:toDestination:overwrite:password:error:delegate:] in SSZipArchive.o
"_unzOpenCurrentFilePassword", referenced from:
+[SSZipArchive unzipFileAtPath:toDestination:overwrite:password:error:delegate:] in SSZipArchive.o
"_zipClose", referenced from:
-[SSZipArchive close] in SSZipArchive.o
"_unzGoToNextFile", referenced from:
+[SSZipArchive unzipFileAtPath:toDestination:overwrite:password:error:delegate:] in SSZipArchive.o
"_zipOpenNewFileInZip", referenced from:
-[SSZipArchive writeFile:] in SSZipArchive.o
-[SSZipArchive writeData:filename:] in SSZipArchive.o
"_unzOpen", referenced from:
+[SSZipArchive unzipFileAtPath:toDestination:overwrite:password:error:delegate:] in SSZipArchive.o
"_unzGetCurrentFileInfo", referenced from:
+[SSZipArchive unzipFileAtPath:toDestination:overwrite:password:error:delegate:] in SSZipArchive.o
"_unzReadCurrentFile", referenced from:
+[SSZipArchive unzipFileAtPath:toDestination:overwrite:password:error:delegate:] in SSZipArchive.o
"_zipCloseFileInZip", referenced from:
-[SSZipArchive writeFile:] in SSZipArchive.o
-[SSZipArchive writeData:filename:] in SSZipArchive.o
"_unzGetGlobalInfo", referenced from:
+[SSZipArchive unzipFileAtPath:toDestination:overwrite:password:error:delegate:] in SSZipArchive.o
"_unzOpenCurrentFile", referenced from:
+[SSZipArchive unzipFileAtPath:toDestination:overwrite:password:error:delegate:] in SSZipArchive.o
"_unzClose", referenced from:
+[SSZipArchive unzipFileAtPath:toDestination:overwrite:password:error:delegate:] in SSZipArchive.o
"_zipOpen", referenced from:
-[SSZipArchive open] in SSZipArchive.o
"_zipWriteInFileInZip", referenced from:
-[SSZipArchive writeFile:] in SSZipArchive.o
-[SSZipArchive writeData:filename:] in SSZipArchive.o
"_unzGoToFirstFile", referenced from:
+[SSZipArchive unzipFileAtPath:toDestination:overwrite:password:error:delegate:] in SSZipArchive.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Conditional unzip of files within a zip file?

Hi,

When using SSZipArchive to extract the contents of an archive, we usually only need 1-2 files out of the dozens within the zip file, so extracting them all is pretty wasteful.

I'm planning to add a zipArchiveShouldUnzipFile: method to the delegate that will allow it to decide whether an individual file gets unzipped, which will be called before the WillUnzip method. Does this fit with your plans for SSZipArchive, and if so should I submit a pull request to incorporate this functionality into the main branch once I'm done?

Thanks for your help.

File modification date is lost when unzipping with SSZipArchive

Hi. I'm using SSZipArchive in a MacOS X application. I'm noticing that when I unzip my archive using my app, the file modification dates are set to the current time. However, if I double click the same .zip in the Finder, the file modification dates are correct.

Xcode update analyze tool issue

In unzip.c on "if (ZSEEK64(s->z_filefunc, s->filestream,
s->pfile_in_zip_read->pos_in_zipfile +
s->pfile_in_zip_read->byte_before_the_zipfile,
SEEK_SET)!=0)", the analyzer says "The right operand '+' is a garbage value, how to get rid of this? This appears in the newest Xcode update

Should be able to zip whole folder & maintain structure & sub structures

it would be great.. (well.. necessary) to have a method

  • (BOOL)createZipFileAtPath:(NSString )path withFolder:(NSString)folderPath;

that would recurse through the folder, maintaining sub folder structures..

unzipping the results would yield a clone of the original folder..

for first rev, I wouldn't care about sym links.

possibly in addition to

  • (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)filenames;

because I could see where you may want a single folder with files zipped from random spots (current implementation)

Delegate gives improper file indexes

The unzipping delegate gives a larger number than the actual number of files in the delegate. It can be used reliably for progress, but the actual numbers are inaccurate.

Detect if zip has a passcode?

All my zips i just unzip but how do i check if it has a passcode? Will SSZipArchive detect it and ask for the password? Zips are downloaded from the internet so I don't know if they has a passcode and only want to ask for one from user if it does

Stuck in an infinite loop when archiving.

Heya, I realize I may be doing something stupid, so please bear with me for now.

I'm trying to archive a folder on iOS using this library, but I'm not having any luck at all.

/Temp/data/metadata
/Temp/data/images
/Temp/data/images/thumbnails
/Temp/data/images/full_res

I'm trying to archive the "data" directory and make it include all it's contents, including the subdirectories, so I have done this:

 NSString *dataPath = [(FTIBAppDelegate *)[[UIApplication sharedApplication] delegate] getDataPath]; //We are zipping the entire data folder.

//....

NSString *saveTo = [NSString stringWithFormat:@"%@/%@", [(FTIBAppDelegate *)[[UIApplication sharedApplication] delegate] getDocumentsPath], archiveName, nil];

//....

[SSZipArchive createZipFileAtPath:saveTo withFilesAtPaths:@[dataPath]];

When I saw my code turned unresponsive after this, I tried to look into the root of the problem, and indeed, when that method calls SSZipArchive's writeFile method, the code is stuck in an infinite loop.

- (BOOL)writeFile:(NSString *)path {
    NSAssert((_zip != NULL), @"Attempting to write to an archive which was never opened");

    FILE *input = fopen([path UTF8String], "r");
    if (NULL == input) {
        return NO;
    }

    zipOpenNewFileInZip(_zip, [[path lastPathComponent] UTF8String], NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED,
                        Z_DEFAULT_COMPRESSION);

    void *buffer = malloc(CHUNK);
    unsigned int len = 0;
//THE CULPRIT IS RIIIIIIIIIIIIIGHT HERE
////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
    while (!feof(input)) {
        len = (unsigned int) fread(buffer, 1, CHUNK, input);
        zipWriteInFileInZip(_zip, buffer, len);
        NSLog(@"infinite loop?");
    }

    zipCloseFileInZip(_zip);
    free(buffer);
    return YES;
}

"input" never reaches end of file. And therefore it's stuck there.

I have tried to deal with this in two ways and nothing has worked at all.

  1. First, I tried all the libz that XCode 5 includes by default. That is libz.dylib, libz.1.dylib, libz.1.1.3.dylib, libz.1.2.5.dylib and it hasn't worked. (I tried them all because the readme doesn't state which one is recommended - none of them worked so this is probably not a problem with the core library).

  2. I have tried to get rid of the subdirectories. My "metadata" directory contains three .json files. I have tried to zip this directory only and it's also stuck in an infinite loop.

Any help with this will be appreciated.

SSZipArchive Won't Open In-App Purchase .zip (Apple Hosted Content)

I'm trying to unzip a .zip file downloaded for an In-App Purchase with Apple Hosted Content. I can open the file if I drag it from iTunes to my desktop, but not using the utility class. The code to unzip it is below. I'd be glad to post the .zip file if I could find a way to do so, but it doesn't appear to be possible.

Charlie

  • (void) completeTransaction : (SKPaymentTransaction *) transaction
    {
    NSLog(@"completeTransaction...");

    if (transaction.downloads)
    {
    [[SKPaymentQueue defaultQueue] startDownloads : transaction.downloads];
    }
    else
    {
    // TODO: Unlock feature or content here before finishing transaction...

    [self provideContentForProductIdentifier : transaction.payment.productIdentifier];
    [[SKPaymentQueue defaultQueue] finishTransaction : transaction];
    

    }

}

  • (void) paymentQueue : (SKPaymentQueue *) queue updatedDownloads : (NSArray *) downloads
    {
    for (SKDownload * download in downloads)
    {
    switch (download.downloadState)
    {
    case SKDownloadStateActive:
    {
    switch ((int) download.progress)
    {
    case SKDownloadStateWaiting: // Download is inactive, waiting to be downloaded
    {
    NSLog(@"SKDownloadStateActive(): Download progress = SKDownloadStateWaiting (%f)", download.progress);
    }

                break;
    
                case SKDownloadStateActive: // Download is actively downloading
                {
                    NSLog(@"SKDownloadStateActive(): Download progress = SKDownloadStateActive (%f)", download.progress);
                }
    
                break;
    
                case SKDownloadStatePaused: // Download was paused by the user
                {
                    NSLog(@"SKDownloadStateActive(): Download progress = SKDownloadStatePaused (%f)", download.progress);
                }
    
                break;
    
                case SKDownloadStateFinished: // Download is finished, content is available
                {
                    NSLog(@"SKDownloadStateActive(): Download progress = SKDownloadStateFinished (%f)", download.progress);
                }
    
                break;
    
                case SKDownloadStateFailed: // Download failed
                {
                    NSLog(@"SKDownloadStateActive(): Download progress = SKDownloadStateFailed (%f)", download.progress);
                }
    
                break;
    
                case SKDownloadStateCancelled: // Download was cancelled
                {
                    NSLog(@"SKDownloadStateActive(): Download progress = SKDownloadStateCancelled (%f)", download.progress);
                }
    
                break;
    
                default:
                {
    
                }
    
                break;
            }
    
            NSLog(@"SKDownloadStateActive(): Download time = %f", download.timeRemaining);
        }
    
        break;
    
        case SKDownloadStateFinished:
        {
            NSLog(@"SKDownloadStateFinished(): .zip file = %@", download.contentURL);
    
            // Download is complete. Content is at path referenced by download.contentURL. Unzip to /Documents directory...
            NSString * destFilename = [self cacheContent : download];
    
            [self provideContentForProductIdentifier : download.transaction.payment.productIdentifier];
            [[SKPaymentQueue defaultQueue] finishTransaction : download.transaction];
    
            if (destFilename != nil)
            {
                [self extractContent: destFilename];
            }
            else
            {
                // Report error to user...
            }
        }
    
        break;
    
        default:
        {
    
        }
    
        break;
    }
    

    }
    }

  • (NSString *) cacheContent : (SKDownload *) download
    {
    // Download is complete. Content is at path referenced by download.contentURL. Unzip to /Documents directory...
    NSArray * docsDirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString * docsDirPath = [docsDirPaths objectAtIndex : 0];
    NSLog(@"docsDirPath = %@", docsDirPath);

    NSString * destFilename = [docsDirPath stringByAppendingPathComponent : download.contentIdentifier];
    destFilename = [destFilename stringByAppendingString: @".zip"];
    NSLog(@"destFilename = %@", destFilename);

    NSFileManager * fileManager = [NSFileManager defaultManager];

    NSError * error;

    if ([fileManager fileExistsAtPath : destFilename])
    {
    [fileManager removeItemAtPath : destFilename error : &error];
    }

    if ([fileManager copyItemAtPath : [download.contentURL path] toPath : destFilename error : &error] == NO)
    {
    destFilename = nil;
    }

    return (destFilename);
    }

  • (void) extractContent : (NSString *) zipFile
    {
    NSArray * docsDirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString * docsDirPath = [docsDirPaths objectAtIndex : 0];

    BOOL unzipped = [SSZipArchive unzipFileAtPath :zipFile toDestination : docsDirPath];

    if (unzipped == YES)
    {
    NSLog(@".zip was extracted successfully...");
    }
    else
    {
    NSLog(@".zip could not be extracted successfully...");
    }

    NSFileManager * fileManager = [NSFileManager defaultManager];
    NSError * error;
    [fileManager removeItemAtPath : zipFile error : &error];
    }

Not getting folder zipping functionality when import with pod.

I am using this in my one project and have need to create zip file with folder structure.

I am using this project by pod.

I ma not getting following function when pod download this project in mine:

+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath;

I have remove pod and try to add it again but not getting any update.

Not Unzipping Files > 2 GB

I'm trying to Unzip a file over 2GB (2.69 GB Precisely).
I'hv implemented the following method to unzip File;

  • (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(id)delegate;

[SSZipArchive unzipFileAtPath:sourcePath toDestination:destinationPath delegate:self];
Which returns NO.

I Debugged the problem & found out that I Get the UNZ_BADZIPFILE in function unzOpenInternal(). I cross checked with the zip file & its unzipping correctly.
I'm stuck, Please let me know how do I get this working. A quick response will be highly valuable & appreciable.

unzipFileAtPath skips folders with accented characters

I am using ssziparchive to extract zip files into the Documents directory of my ios application. If the path of the zipped files contains accented characters (f.e. á é í ó ú) they are skipped.

Sample zip file:

/
-- folder1/
-----file1
-----file2
-----file3
-- fólder2/
-----file1
-----file2
-- folder3/
-----file1
-----file2

Result:

/
-- folder1/
-----file1
-----file2
-----file3
-- folder3/
-----file1
-----file2

I don't know if I missing something or it is a bug.

Thanks.

Potential thread issue for zipping large or multiple files

I came across this recently, and really don't know where to look into. The situation I use SSZipArchive is like this: in app's documents directory there's a folder with several audio file within, all in .aac format. I need to zip the audio files and upload the zip file onto a server.
At first I simply used [SSZipArchive createZipFileAtPath:zippedPath withFilesAtPaths:inputPaths] (every time it returns a YES) and then upload; later I noticed the zip file might fail to contain the correct amount of audio files, i.e. originally 7 audio files, after zipping, only 3 or 4 or sometimes even nothing zipped.
So I run a test with NSOperationQueue to zip 100 times in the same situation, and when it comes to the 26th or 27th (not always, but somewhere around), the zip file will fail to contain all the 7 audio files.

unzip problem

When I unzip a .bundle file from zip. My bundle file was damaged, couldn't load anymore. "Reason: no suitable image found. "
But if I click to unzip the zip file, the .bundle file can be loaded in my program.

Add progress delegate

Either by file number out of total files or number of bytes unzipped out of the total. Not sure which is more accurate.

Non-POSIX zips get extracted with missing permissions

When extracting a zip that has non-POSIX style permissions, the files are extracted with no permissions (0 value to be specific).

As an example, a zip from a Windows computer will be extracted with 0-valued permissions. If necessary, I can provide an example archive as Objective C developers may not have Windows handy :).

Edit

I have created a pull request with a change that leaves permissions alone unless the file in the archive has non-0 permission bits.

I wish I could figure out how to tie this issue and the pull request together, but I can't figure out how, so here's the pull request: #65


Original content:

I plan to make a pull request at some point in the near future with a new method:

+ (BOOL)unzipFileAtPath:
    (NSString *)path toDestination:(NSString *)destination 
    overwrite:(BOOL)overwrite password:(NSString *)password 
    error:(NSError **)error delegate:(id<SSZipArchiveDelegate>)delegate
    retainPermissions:(BOOL)retainPermissions retainDates:(BOOL)retainDates;

The two new parameters would of course default to true as to retain old behavior.

I'm new to both Objective C and contributing to projects, so please let me know if I'm headed down the wrong path (perhaps I should just make it check if the permissions are 0 instead of new parameters?) or if this contribution would not be welcomed.

Cannot update UI.

Before i was able to update the UI, now even with dispatch_async(dispatch_get_main_queue(), ^{}); nothing will update, even if i change the UI before i call [SSZipArchive unzipFileAtPath:zipPath toDestination:self.currentPath delegate:self];

Large File -

Hi,

The file I'm unzipping has just grown to 2.3GB and I'm now getting UNZ_BADZIPFILE while unzipping. The unzipped file is around 7GB.

The error is occurring in the following check:

    if ((number_entry_CD!=us.gi.number_entry) ||
        (number_disk_with_CD!=0) ||
        (number_disk!=0))
        err=UNZ_BADZIPFILE;

The documentation of this makes it sound like it's getting an incorrect number of files from the zip archive - is that right?

I'm just using the built in compress tool in OS X to compress the file (as has worked previously).

Thanks!

Luke

Undefined symbols for architecture armv7

Undefined symbols for architecture armv7:
"OBJC_CLASS$_SSZipArchive", referenced from:
objc-class-ref in LoginVC.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

any ideas?

Zips larger than 2GB

It appears not to unzip files larger than 2GB. Do you think there is a hard set limitation somewhere?

SIGTRAP when ziping a directory on the commandline

I tried to extract a zip file which I've crafted using the standard linux zip command by do so:

zip -q -r commandline-version.zip index.json web/

When I try to extract it with

[SSZipArchive unzipFileAtPath:@"commandline-version.zip" toDestination:dest];

it ends up in a SIGTRAP. EDIT: Before it ends up in a SIGTRAP there are some files extracted.

So I was curious and tried several things when creating the zip file. All variations of the zip command weren't honored with any success. But when I zip the files in Finder.app with its archive action from the context menu, the extraction within iOS succeeded.

Any ideas?

I uploaded the both zip files in question:

PS: I use SSZipArchive via its CocoaPods podspec.

Path inclusive #include "minizip/unzip.h" breaks CocoPod

It would seem the #include "minizip/unzip.h" breaks in 2.2.3 when used as a CocoaPod. The podspec says:

s.preserve_paths = 'minizip'

But the header search path in the Pods.xcconfig remains simply "${PODS_ROOT}/BuildHeaders/SSZipArchive" and the "${PODS_ROOT}/BuildHeaders/SSZipArchive" directory is flat.

Changing the include to:

#include "unzip.h"

solves the issue, for me.

Create zip with password protection

Hello

It would be great if we could have a method like :

  • (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)filenames overwrite:(BOOL)overwrite password:(NSString *)password;

Thanks

Cancel Zip file

i use SSZipArchive for zip file, but i have a problem. I want to cancel zip file when i call function

(BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths

Thanks :)

Problem with Zipping folders

Hi! I've find SSZipArchive very useful! There is a problem when I try to zip a folder path. The writeFile: method doesn't find the end of file (because isn't a file!) and continue to run in whlie mode. this can be fixed? And it can be created a method that zip an entire folder like zipDirectory:(NSString *)directoryPath ?

TY

Lorenzo

unzip with password

unzip.c
in line 72

define NOUNCRYPT

leads to bail out in line 1493 without opening the password protected archive

Some files are truncated when unzipping.

For instance, this archive contains an index.json file which is consistently truncated, while unzipping it with other tools does work correctly.

I won’t be working on this client project for a while, so I can’t say when/if I will get to this myself, but I wanted to at least report a reproducible issue in case anyone else gets to it sooner.

Cast pointer to int potentially losing precision in 64bit environment

Appears to be casting of pointer to (int).
https://github.com/soffes/ssziparchive/blob/master/SSZipArchive/minizip/unzip.c#L218

According to Apple 64-bit transition guide, this would result in loss of precision when assigned back to ptr. They suggest using uintptr_t.

https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaTouch64BitGuide/ConvertingYourAppto64-Bit/ConvertingYourAppto64-Bit.html#//apple_ref/doc/uid/TP40013501-CH3-SW3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.