zip file I/O library for iOS, macOS and tvOS

Related tags

Files ZipZap
Overview

Build Status

ZipZap is a zip file I/O library for iOS, macOS and tvOS.

The zip file is an ideal container for compound Objective-C documents. Zip files are widely used and well understood. You can randomly access their parts. The format compresses decently and has extensive operating system and tool support. So we want to make this format an even easier choice for you. Thus, the library features:

  • Easy-to-use interface: The public API offers just two classes! Yet you can look through zip files using familiar NSArray collections and properties. And you can zip, unzip and rezip zip files through familiar NSData, NSStream and Image I/O classes.
  • Efficient implementation: We've optimized zip file reading and writing to reduce virtual memory pressure and disk file thrashing. Depending on how your compound document is organized, updating a single entry can be faster than writing the same data to a separate file.
  • File format compatibility: Since ZipZap closely follows the zip file format specification, it works with most Mac, Linux and Windows zip tools.

Install

As an independent project:

  • In the Terminal, run git clone https://github.com/pixelglow/ZipZap.git.
  • Within the ZipZap directory, open the ZipZap.xcodeproj Xcode project.
  • In the Xcode project, select either the ZipZap (iOS Framework), ZipZap (iOS Static Library), ZipZap (macOS Framework), ZipZap (macOS Static Library), ZipZap (tvOS Framework) or ZipZap (tvOS Static Library) scheme from the drop down.
  • You can now build, test (macOS only) or analyze with the selected scheme.
  • The built libraries and test cases are in a subdirectory of ~/Library/Developer/Xcode/DerivedData.

As a project integrated with your own workspace:

  • In the Terminal, run cd workspace then git submodule add https://github.com/pixelglow/ZipZap.git.
  • In your Xcode workspace, choose the File > Add Files to "workspace" menu item, then within the ZipZap directory pick the ZipZap.xcodeproj Xcode project.
  • In any project target that will use ZipZap:
    • In Build Phases > Link Binary With Libraries, add the corresponding libZipZap.a and any other library listed in the Require Link section below.
    • Under Build Settings > Search Paths > Header Search Paths, add ../ZipZap.
  • You can now build, test or analyze those project targets.

Use

Header includes:

#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]);

Writing a new zip file:

ZZArchive* newArchive = [[ZZArchive alloc] initWithURL:[NSURL fileURLWithPath:@"/tmp/new.zip"]
                                               options:@{ZZOpenOptionsCreateIfMissingKey : @YES}
                                                 error:nil];
[newArchive updateEntries:
                     @[
                     [ZZArchiveEntry archiveEntryWithFileName:@"first.text"
                                                     compress:YES
                                                    dataBlock:^(NSError** error)
                                                          {
                                                              return [@"hello, world" dataUsingEncoding:NSUTF8StringEncoding];
                                                          }]
                     ]
                    error:nil];

Updating an existing zip file:

ZZArchive* oldArchive = [ZZArchive archiveWithURL:[NSURL fileURLWithPath:@"/tmp/old.zip"]
                                            error:nil];
[oldArchive updateEntries:
 [oldArchive.entries arrayByAddingObject:
  [ZZArchiveEntry archiveEntryWithFileName:@"second.text"
                                  compress:YES
                                 dataBlock:^(NSError** error)
                                       {
                                           return [@"bye, world" dataUsingEncoding:NSUTF8StringEncoding];
                                       }]]
                    error:nil];

Advanced uses: Recipes

API references: References

Require

  • Build: Xcode 7 and later.
  • Link: Only system libraries; no third-party libraries needed.
    • ApplicationServices.framework (macOS) or ImageIO.framework (iOS, tvOS)
    • Foundation.framework
    • libz.dylib
  • Run: macOS 10.11 (El Capitan), iOS 9.3 or tvOS 9.2 and later.

Support

License

ZipZap is licensed with the BSD license.

Donate

Comments
  • AES decryption support!

    AES decryption support!

    Took me a while, as WinZip's way of using AES was a little different than what I'm used to. Also I changed the AES block processing code a few times... You may want to modify the git history to your liking ;-)

    opened by danielgindi 34
  • Use of zipzap CocoaPod disables exception support project-wide

    Use of zipzap CocoaPod disables exception support project-wide

    As described in some of the comments on #71, the mere inclusion of the zipzap CocoaPod in a project seems to have the effect of turning off support for Objective-C exceptions on a project-wide basis. For existing code and dependencies that are not easily altered, this is a blocker.

    Earlier, I addressed the problem by ensuring a project-level setting was in force for GCC_ENABLE_OBJC_EXCEPTIONS = YES. After updating to CocoaPods 0.34.1 today and ensuring that a complete list of link_with targets are specified in my Podfile, this no longer works—the setting is superseded project-wide by zipzap.

    As a further work-around, I moved this build setting to target-level on all affected targets in the project. While this now allows a build, it first creates a ton of spew when pod install is run:

    [!] The `Kashoo [Development]` target overrides the `GCC_ENABLE_OBJC_EXCEPTIONS` build setting defined in `Pods/Target Support Files/Pods/Pods.development.xcconfig'. This can lead to problems with the CocoaPods installation
        - Use the `$(inherited)` flag, or
        - Remove the build settings from the target.
    

    This message is repeated for every build configuration on every target (4 targets x 3 configurations = 12 warnings in my case).

    opened by zygoat 16
  • Error handling

    Error handling

    At present Zipzap makes relatively little allowance for error-handling, which worries me:

    • [x] In ZZFileChannel, the call to open might fail due to the URL being unsuitable, or a permissions problem. There is no way to indicate that to the caller beyond the likelihood of NSFileHandle blowing up
    • [x] If writing data to the file handle fails midway through, NSFileHandle is documented to throw an exception. I don't think the code handles this at present, and users of Zipzap aren't advised that such a situation might arise
    • [x] Also in ZZFileChannel, the -openInput method completely ignores the NSError object, so clients have no idea why it might have failed
    opened by mikeabdullah 15
  • In-memory zip generation

    In-memory zip generation

    In my app, I'd like to generate the data for a zip file entirely in-memory without touching the disk. The data is to be uploaded to a remote server, so there's no need for it to touch the local disk, and avoiding so means no file access errors can occur.

    Looking through ZZMutableArchive, this looks a bit tricky to achieve. It seems the current code is built atop NSFileHandle. I could create a custom subclass of NSFileHandle that is backed by data, but that seems rather messy, and perhaps would fail in some places.

    Using NSOutputStream instead would make my life easier. So, what in NSFileHandle are we dependent on? Looking at the code:

    • -offsetInFile to track how much data has been written so far; this could be replaced by passing round integers as arguments/return values
    • If an error occurs while writing an entry, winds the file handle back to where it was before that entry was written
    • -truncateFileAtOffset called once writing is finished; as I understand it, that mostly is to handle archives which are now smaller than when they were read

    Have I got those right, missed anything?

    opened by mikeabdullah 13
  • Instantiation of decrypted stream is crashing for some zip file (AES 256)

    Instantiation of decrypted stream is crashing for some zip file (AES 256)

    Hi there.

    I am experimenting some crash when trying to unarchive a specific AES256 encrypted zip. The following invocation will crash:

    decryptedStream = [[ZZAESDecryptInputStream alloc] initWithStream:dataStream password:password header:_localFileHeader->fileData() strength:_localFileHeader->extraField<ZZWinZipAESExtraField>()->encryptionStrength error:error]; }

    This is because in some cases the _localFileHeader doesn't contain any data and as a result the encryptionStrength can't be extracted. I have found out that the file was corrupted but i believe we should return an error in this case.

    I have now added this additional sanity check before the creation of the localFileHeader: nextCentralFileHeader->relativeOffsetOfLocalHeader == 0 && *beginContent == '\0

    for the following section:

    NSMutableArray<ZZArchiveEntry*>* entries = [NSMutableArray array];
        for (NSUInteger index = 0; index < endOfCentralDirectoryRecord->totalNumberOfEntriesInTheCentralDirectory; ++index)
        {
            // sanity check:
            if (
                // correct signature
                nextCentralFileHeader->sign != ZZCentralFileHeader::sign
                // single disk zip
                || nextCentralFileHeader->diskNumberStart != 0
                // local file occurs before first central file header, and has enough minimal space for at least local file
                || nextCentralFileHeader->relativeOffsetOfLocalHeader + sizeof(ZZLocalFileHeader)
                    > endOfCentralDirectoryRecord->offsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber
                // next central file header in sequence is within the central directory
                || (const uint8_t*)nextCentralFileHeader->nextCentralFileHeader() > endOfCentralDirectory
                || nextCentralFileHeader->relativeOffsetOfLocalHeader == 0 && *beginContent == '\0')
                return ZZRaiseErrorNo(error, ZZCentralFileHeaderReadErrorCode, @{ZZEntryIndexKey : @(index)});
    
            ZZLocalFileHeader* nextLocalFileHeader = (ZZLocalFileHeader*)(beginContent
                                                                          + nextCentralFileHeader->relativeOffsetOfLocalHeader);
    
            [entries addObject:[[ZZOldArchiveEntry alloc] initWithCentralFileHeader:nextCentralFileHeader
                                                                    localFileHeader:nextLocalFileHeader]];
    
            nextCentralFileHeader = nextCentralFileHeader->nextCentralFileHeader();
        }
    
    
    

    What do you think? If this sounds correct to you i will make a pull request.

    Thanks in advance for your input on that matter.

    opened by ghost 12
  • Not being able to install zipzap on my project

    Not being able to install zipzap on my project

    I've tried to install it with what you wrote on the README but I'm not doing it successfully. That would be nice to post a step-by-step picture 'tutorial'. Thank you

    question 
    opened by pedrovieira 12
  • Podfile excluding headers

    Podfile excluding headers

    Zipzap has been changed to include a list of public headers in the podspec and the only one listed is zipzap.h. Unfortunately this means that the headers that one references aren't exported. Removing the public_headers line fixes the issue, but I'd assume adding the list of all headers an external project should be able to use would fix this too.

    Steps to reproduce:

    • Create a new project in Xcode
    • Add a Podfile with zipzap listed as the only pod
    • Run pod install
    • Add the import for zipzap.h to any class in the project
    • Build
    • Observe error in zipzap.h: "ZZArchive.h file not found"
    opened by parrots 10
  • Document how to work with directories

    Document how to work with directories

    I see there's support for creating a ZZArchiveEntry that represents a directory, but have no idea how to actually populate it, or indeed find out its contents.

    question 
    opened by mikeabdullah 10
  • ZZEndOfCentralDirectoryReadErrorCode Error

    ZZEndOfCentralDirectoryReadErrorCode Error

    Hello,

    My name is Josh and I have been using your library for some time. Firstly, I would like to say that it is fantastic.

    Recently, I have had error reports from users, which I have worked this out to be something going wrong with our zipping code. Specifically, I am getting an ZZEndOfCentralDirectoryReadErrorCode from the ZipZap library.

    I was wondering if you could explain what an End of Central Directory Read error is and in what circumstances it can occur.

    Thanks in advance for any insights you can offer.

    Cheers

    opened by joshfuggle 8
  • Update zipzap.podspec

    Update zipzap.podspec

    Update podspec version from 6.0 to 6.1. Release version (tags) are mapped to a certain commit. 6.0 is mapped to 7fe656be30e550b97258579a6763a09c59bfd660

    Cocoapods clones that commit in stead of c27f9e101eb545b464c16595fbac7c326203cc41 - the one that has the latest podspec and the AES encryption support.

    Updating the podspec version to 6.1 and creating a new release (6.1) would allow CocoaPods to clone the correct version.

    opened by cyupa 8
  • Xcode 5 arm64 error

    Xcode 5 arm64 error

    Hi, I'm building an iPhone app with support for iOS 6.0 and above.

    Using Xcode 5, I'm getting the following error: "Invalid deployment target '6.0.0' for architecture 'arm64' (requires '7.0.0' or later)"

    My guess is that the library is not deployed for iPhone 5s architecture.

    opened by oscarvgg 8
  • Swift Package

    Swift Package

    Can anyone tell me how to import the ZipZap dependency into our XCode project without using Swift as there is no Swift package available?

    Showing All Messages https://github.com/pixelglow/ZipZap.git has no Package.swift manifest

    opened by Iain2612 0
  • New clang compiler complains tautology in this code

    New clang compiler complains tautology in this code

    https://github.com/pixelglow/ZipZap/blob/master/ZipZap/ZZArchive.mm#L149

    This line pointing to a static int sign: https://github.com/pixelglow/ZipZap/blob/master/ZipZap/ZZHeaders.h#L151

    Should this be signature?

    opened by liuliu 1
  • Archiving release version of ZipZap

    Archiving release version of ZipZap

    Hi,

    When archiving ZipZap an empty archive is created. This can be remedied by setting the 'Build Setting' 'Skip Install' to 'No' for Release builds. Please consider this change.

    Kind regards,

    Remco Poelstra

    opened by rpoelstra 0
  • Unable to Build Xcode 10 Beta

    Unable to Build Xcode 10 Beta

    Xcode has appletvsimulator12.0 installed and id:BD6947F6-C0D6-43C0-B35A-30C3F83A48CE matches

    xcodebuild: error: Unable to find a destination matching the provided destination specifier:
    		{ platform:tvOS Simulator, id:BD6947F6-C0D6-43C0-B35A-30C3F83A48CE }
    
    	Ineligible destinations for the "ZipZap (tvOS Framework)" scheme:
    		{ platform:tvOS, id:dvtdevice-DVTiOSDevicePlaceholder-appletvos:placeholder, name:Generic tvOS Device }
    		{ platform:tvOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-appletvsimulator:placeholder, name:Generic tvOS Simulator Device }```
    
    opened by shaynem 0
Releases(8.1)
  • 8.1(Nov 7, 2015)

    • Fix last modified date inaccurately stored.
    • Fix exception build settings, especially with CocoaPods.
    • Target iOS, OS X and tvOS frameworks.
    • Add modern initializers, nullability and lightweight generics.
    • Add fine-grained filename encoding.

    Note: this is a breaking change for accessing non-ASCII zip entry fileName created by non-conforming zip programs e.g. the Mac OS X zip command line. Use fileNameWithEncoding: to force a particular encoding instead.

    Source code(tar.gz)
    Source code(zip)
  • 8.0(Sep 4, 2014)

    • Fix low mmap underflow crash.
    • Fix inflate buffer leak when decompressing entire data.
    • Fix library not linking on simulator build.
    • Ensure fileData is actually copied when reading uncompressed zip files.
    • Decrypting with wrong password now errors immediately
    • Improve archive init API.
    Source code(tar.gz)
    Source code(zip)
  • 7.0(Mar 24, 2014)

  • 6.0(Mar 24, 2014)

    • Fix temporary directories not being removed.
    • Fix output stream status not updating.
    • Fix writing entries >2G erroring with POSIX error EINVAL.
    • Reduce memory usage.
    • newData and newStream API
    Source code(tar.gz)
    Source code(zip)
  • 5.0(Mar 24, 2014)

Owner
Glen Low
Glen Low
Edit a file, create a new file, and clone from Bitbucket in under 2 minutes

Edit a file, create a new file, and clone from Bitbucket in under 2 minutes When you're done, you can delete the content in this README and update the

Nikunj Munjiyasara 0 Nov 9, 2021
ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS.

SSZipArchive ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS. Unzip zip files; Unzip password protected zi

ZipArchive 5.2k Jan 2, 2023
FileExplorer is a powerful iOS file browser that allows its users to choose and remove files and/or directories

FileExplorer (iOS 9.0+) ?? Project created and maintained by Rafał Augustyniak. You can find me on twitter (@RaAugustyniak). Introduction FileExplorer

Rafał Augustyniak 717 Dec 19, 2022
Zero-setup P2P file transfer between Macs and iOS devices

?? Ares Zero-setup* P2P file transfer between Macs and iOS devices Ares is a service that I built in under 24 hours, winning first place at HackED 201

Indragie Karunaratne 131 Jan 10, 2022
FileKit is a Swift framework that allows for simple and expressive file management.

FileKit is a Swift framework that allows for simple and expressive file management.

Nikolai Vazquez 2.2k Jan 7, 2023
A micro-framework for observing file changes, both local and remote. Helpful in building developer tools.

KZFileWatchers Wouldn't it be great if we could adjust feeds and configurations of our native apps without having to sit back to Xcode, change code, r

Krzysztof Zabłocki 1k Dec 19, 2022
File management and path analysis for Swift

Pathos offers cross-platform virtual file system APIs for Swift. Pathos is implement from ground-up with on each OS's native API. It has zero dependen

Daniel Duan 104 Nov 19, 2022
RavynOS File manager built in Cocoa/Appkit and ObjC

Filer A file manager and re-implementation of macOS's Finder. A key component of ravynOS, Filer is the first application you see after you start ravyn

RavynSoft 8 Oct 3, 2022
NV_MVVM-C is a template file generator. This can reduce the time taken to write the boilerplate code and create the files.

NV_MVVM-C Template, is an MVVM-C Boilerplate generator which will help you generate all the necessary files for your project architected in MVVM-C.

Nikhil Vinod 9 Sep 6, 2022
'Root' filesystem File Provider extension for iOS.

RootFSProvider This sample project was previously available on on Patreon. It is written in Objective-C, and has not been updated for newer APIs since

Steven Troughton-Smith 14 Sep 24, 2022
Finder-style iOS file browser written in Swift

FileBrowser iOS Finder-style file browser in Swift 4.0 with search, file previews and 3D touch. Simple and quick to use. Features ✨ Features ?? Browse

Roy Marmelstein 1.5k Dec 16, 2022
🎹 MIDIKit extension for SMF (Standard MIDI File)

?? SMF (Standard MIDI File) Extension for MIDIKit This extension adds abstractions for reading and writing Standard MIDI Files. Getting Started Add MI

Steffan Andrews 3 Aug 30, 2022
SwiftXLSX - A library focused creating Excel spreadsheet (XLSX) files directly on mobile devices

SwiftXLSX Excel spreadsheet (XLSX) format writer on pure SWIFT. SwiftXLSX is a l

null 19 Dec 13, 2022
FileManager replacement for Local, iCloud and Remote (WebDAV/FTP/Dropbox/OneDrive) files -- Swift

This Swift library provide a swifty way to deal with local and remote files and directories in a unified way. This library provides implementaion of W

Amir Abbas Mousavian 890 Jan 6, 2023
Swift framework for zipping and unzipping files.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Roy Marmelstein 2.3k Dec 30, 2022
zip file I/O library for iOS, macOS and tvOS

ZipZap is a zip file I/O library for iOS, macOS and tvOS. The zip file is an ideal container for compound Objective-C documents. Zip files are widely

Glen Low 1.2k Dec 27, 2022
An Adobe .ase (Adobe Swatch Exchange File), .aco (Photoshop swatch file) reader/writer package for Swift (macOS, iOS, tvOS, macCatalyst)

ColorPaletteCodable A palette reader/editor/writer package for iOS, macOS, watchOS and tvOS, supporting the following formats Adobe Swatch Exchange (.

Darren Ford 11 Nov 29, 2022
Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri

Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri. This plugin is similar to cordova-plugin-file-opener2 without installation support.

Capacitor Community 32 Dec 21, 2022
The sample implementation of zip-archived document for a macOS AppKit platform.

The sample implementation of zip-archived document for a macOS AppKit platform. You can implement NSDocument-based I/O of archived document in your application like .sketch or .key.

usagimaru 4 Nov 12, 2022
CachyKit - A Caching Library is written in Swift that can cache JSON, Image, Zip or AnyObject with expiry date/TTYL and force refresh.

Nice threadsafe expirable cache management that can cache any object. Supports fetching from server, single object expire date, UIImageView loading etc.

Sadman Samee 122 Dec 28, 2022