Search code examples
ioscryptographyapp-storessziparchive

It is allowed to use ssziparchive library in the App Store?


Due to cryptography export regulations, it is possible to use this library? or which one could I use to compress/decompress files?


Solution

  • I don't know if SSZipArchive is allowed to use in distributed apps, but the library I am using is Objective-Zip.

    It can be easily integrated into any project.

    Sample code for zipping:

    // create a zip file for writing
    ZipFile *zipFile= [[ZipFile alloc] initWithFileName:pathOfTheFileToBeZipped mode:ZipFileModeCreate];
    
    // Add a file, write to its stream and close it
    ZipWriteStream *stream1= [zipFile writeFileInZipWithName:@"abc.txt" fileDate:[NSDate dateWithTimeIntervalSinceNow:-86400.0] compressionLevel:ZipCompressionLevelBest];
    NSString *text= @"abc";
    [stream1 writeData:[text dataUsingEncoding:NSUTF8StringEncoding]];
    [stream1 finishedWriting];
    
    // Add another file, write to its stream and close it
    ZipWriteStream *stream2= [zipFile writeFileInZipWithName:@"x/y/z/xyz.txt" compressionLevel:ZipCompressionLevelNone];
    NSString *text2= @"XYZ";
    [stream2 writeData:[text2 dataUsingEncoding:NSUTF8StringEncoding]];
    [stream2 finishedWriting];
    
    // Close the zip file
    [zipFile close];
    

    Sample code for unzipping:

    // open the zip file for reading
    ZipFile *unzipFile = [[ZipFile alloc] initWithFileName:pathOfTheFileToBeUnzipped mode:ZipFileModeUnzip];
    
    // retrieve the info of the files inside
    NSArray *infos= [unzipFile listFileInZipInfos];
    
    // iterate over files
    for (FileInZipInfo *info in infos) {        
        // locate the file in the zip
        [unzipFile locateFileInZip:info.name];
    
        // expand the file in memory
        ZipReadStream *read= [unzipFile readCurrentFileInZip];
        NSData *data = [read readDataOfLength:info.length];
        [read finishedReading];
    
        // construct the folder/file path structure
        NSString *unzipPathFilename = [unzipPath stringByAppendingPathComponent:info.name];
        NSString *unzipPathFoldername = [[unzipPathFilename stringByDeletingLastPathComponent] copy];
        NSError *errorw;
    
        // write the unzipped files, with some consistency checks
        NSRange range = [unzipPathFoldername rangeOfString:@"__MACOSX"];
    
        if (range.location == NSNotFound) {
            if ([fileManager createDirectoryAtPath:unzipPathFoldername withIntermediateDirectories:YES attributes:nil error:&errorw]) {
                if (![[unzipPathFilename pathExtension] isEqualToString:@""] && ![[[unzipPathFilename lastPathComponent] substringToIndex:1] isEqualToString:@"." ]) {
                    [data writeToFile:unzipPathFilename atomically:NO];
                }
            }
            else {
                NSLog(@"Directory Fail: %@", errorw);
            }
        }
    }
    
    // close the zip file
    [unzipFile close];