1

I'm using the Objective-Zip to create a zip files, but it is not working and Xcode says that have many deprecation and issues. The first thing Is import all the classes inside the folders:

ARCHelper, ZLib, MiniZip, Objective-Zip

To my project, now I need to create a zip file, for this I use this code:

#import "ZipFile.h"
#import "ZipWriteStream.h"

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString* str = @"teststring";
    NSData* abcData = [str dataUsingEncoding:NSUTF8StringEncoding];

    ZipFile *zipFile= [[ZipFile alloc] initWithFileName:@"test.zip"
                                                   mode:ZipFileModeCreate];

    ZipWriteStream *stream = [zipFile writeFileInZipWithName:@"abc.txt"
                                           compressionLevel:ZipCompressionLevelBest];

    [stream writeData:abcData];
    [stream finishedWriting];

    [zipFile close];   
}

When I build and run this code I receive the message:

*** Terminating app due to uncaught exception 'ZipException', reason: 'Can't open 'test.zip''

First, I create a zip file, not try to open him (So the message in console are wrong is 'can't create test.zip' not 'open').

Knowing about errors that are giving, I believe that this class of objective-zip is already old, I wonder if there is another class better than this in which I can create zip files (and set passwords for these files).

LettersBa
  • 747
  • 1
  • 8
  • 27
  • 1
    You need to pass the full path to the zip file, not just the filename. – rmaddy Apr 27 '15 at 14:46
  • I believe @rmaddy is correct. You need to specify the full path. I noticed you tried this after another answer, but the answer has been deleted. There you said it failed with null file. I think you perhaps passed a nil string that time as looking at the source code it coverts NString into a C string which has ended up as a null pointer. I would try again with a full path and check its not nil. – Rory McKinnel Apr 27 '15 at 20:33

2 Answers2

2

I recommend you using the following library: https://github.com/pixelglow/zipzap

To use it just import the header files:

#import <zipzap/zipzap.h>

Reading an existing zip file:

ZZArchive* oldArchive = [ZZArchive archiveWithURL:[NSURL fileURLWithPath:@"/tmp/old.zip"]
                                        error:nil];
ZZArchiveEntry* firstArchiveEntry = oldArchive.entries[0];
NSLog(@"The first entry's uncompressed size is %lu bytes.", (unsigned long)firstArchiveEntry.uncompressedSize);
NSLog(@"The first entry's data is: %@.", [firstArchiveEntry newDataWithError:nil]);
Manuel Escrig
  • 2,825
  • 1
  • 27
  • 36
1

Try using an open source version. One is mentioned in this answer.

How to unzip a .zip file on iOS?

The packaged referenced is SSZipArchive: https://github.com/soffes/ssziparchive

Community
  • 1
  • 1
Rory McKinnel
  • 7,936
  • 2
  • 17
  • 28
  • The ssziparchive don't create zip files with passwords... – LettersBa Apr 27 '15 at 14:35
  • The minizip project it comes with seems to support passwords. You could perhaps extend the class to deal with password on write. It seems to have password for read already. However I notice from another answer you may have an issue with paths. – Rory McKinnel Apr 27 '15 at 15:00
  • Ok @sphanley. Added a link to the project for. – Rory McKinnel Apr 27 '15 at 15:23
  • Hey Guys, think with me! I can't put a password in that zip archive, But I can try to create this zip without password, next I get this file and convert it to NSData and crypt with AES256, and save it again with other format, and If I want to open this file I will get him, decrypt with AES256 to .zip again and use SSZipArchive to unzip files, It will work? – LettersBa Apr 27 '15 at 23:52
  • 1
    That is certainly an option and saves you having to worry about the zip side complexity of dealing with passwords. Should be ok as long as you only have to deal with your own files and not password zipped files from elsewhere. – Rory McKinnel Apr 28 '15 at 09:35
  • Well, This zip file is a backup that store sensitive informations of that user and send users email, Now I learned how to zip files with ZipArchive with passwords, If I zip this backup informations and send to email with backup.zip, and this falls into the wrong hand , he will know that file is zipped and try to break the password. Now If I continue using SSZipArchive with AES256 and send the file with name 'backup.strangeExtension' I believe That it will More Security To File , no? – LettersBa Apr 28 '15 at 13:36