ZippyZap is a ZIP compression file I/O library for macOS, iOS/iPadOS, and tvOS.
It probably goes without saying that ZIP is the most popular compression format in the world. Supported natively by many operating systems, ZIP is completely open, easy to create and consume, and serves as the basis for many other file formats.
ZippyZap is a fork of ZipZap, originally by Glen Low. ZipZap had the goal of being the most comprehensive open source ZIP library for Apple's platforms, adhering to the ZIP standard as closely as possible, and also having a very extensive test suite.
Glen's current working circumstances have made it such that he has unable been able to continue working on ZipZap for the last few years. Since I believe that this is by far the best ZIP library available on the platform, I've forked ZipZap into ZippyZap with the goal of continuing to use and refine it for my own upcoming projects.
- Easy-to-use interface: The public API offers just two classes! You can browse through zip files using familiar
NSArray
collections and properties. And you can zip, unzip and re-zip ZIP files through familiarNSData
,NSStream
andImageIO
classes. - Efficient implementation: ZIP file reading and writing has been optimised to reduce virtual memory pressure and disk file thrashing. Depending on how your archive is organised, updating a single entry can be faster than writing the same data to a separate file.
- File format compatibility: Since ZippyZap closely follows the zip file format specification, it works with most Mac, Linux and Windows ZIP tools.
- Build: Xcode 7 and later.
- Linking:
ApplicationServices.framework
(macOS only)ImageIO.framework
(iOS only)Foundation.framework
libz.dylib
- System: macOS 10.10 (Yosemite) or iOS 7.0 and later.
Include the following line in your
pod 'ZippyZap'
- Download the
ZippyZap
repo to your hard drive and decompress it. - Within the
ZippyZap
directory, open theZippyZap.xcodeproj
project in Xcode. - In the Xcode project, select either the ZippyZap (iOS Framework), ZippyZap (iOS Static Library), ZippyZap (macOS Framework) or ZippyZap (macOS Static Library) scheme from the drop down.
- From the selected scheme, you can build a copy of the framework that you can them embed in your own project.
- The built libraries and test cases are located in a subdirectory of
~/Library/Developer/Xcode/DerivedData
.
- In Terminal, run
cd workspace
thengit submodule add https://github.com/TimOliver/ZippyZap.git
. - In your Xcode workspace, choose File > Add Files to "workspace", and then within the ZippyZap directory pick the ZippyZap.xcodeproj Xcode project.
- In any project target that will use ZippyZap:
- In Build Phases > Link Binary With Libraries, add the corresponding libZippyZap.a and any other library listed in the Require Link section below.
- Under Build Settings > Search Paths > Header Search Paths, add ../ZippyZap.
- You can now build, test or analyse any of those project targets.
Header includes:
#import <ZippyZap/ZippyZap.h>
Read an existing ZIP file:
NSURL *archiveURL = [NSURL fileURLWithPath:@"/tmp/archive.zip"];
// Open the ZIP archive
ZZArchive* archive = [ZZArchive archiveWithURL:archiveURL error:nil];
// Load the first entry from within the archive
ZZArchiveEntry* firstArchiveEntry = archive.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]);
Write a new ZIP file:
// Create a new archive object instance, setting a key to create if missing
ZZArchive* newArchive = [[ZZArchive alloc] initWithURL:newURL
options:@{ZZOpenOptionsCreateIfMissingKey : @YES}
error:nil];
// Create a new entry and populate it with data
id dataBlock = ^(NSError** error) {
return [@"hello, world" dataUsingEncoding:NSUTF8StringEncoding];
};
ZZArchiveEntry *newEntry = [ZZArchiveEntry archiveEntryWithFileName:@"first.text"
compress:YES
dataBlock:dataBlock];
// Add the entry to the archive
[newArchive updateEntries:@[newEntry] error:nil];
Update an existing ZIP file:
// Create a new instance of an archive
NSURL *zipURL = [NSURL fileURLWithPath:@"/tmp/old.zip"];
ZZArchive *archive = [ZZArchive archiveWithURL:zipURL error:nil];
// Create a new entry, and populate it with data
id dataBlock = ^(NSError** error) {
return [@"bye, world" dataUsingEncoding:NSUTF8StringEncoding];
};
ZZArchiveEntry *entry = [ZZArchiveEntry archiveEntryWithFileName:@"second.text"
compress:YES
dataBlock:dataBlock];
// Append it to the existing entries of the archive
[archive updateEntries:[archive.entries arrayByAddingObject:entry] error:nil];
ZippyZap is licensed under the BSD license. Please see the LICENSE file.