From 667b62fcc1ac72978699b793799172745b62bfdf Mon Sep 17 00:00:00 2001 From: Gianluca Bertani Date: Mon, 4 Mar 2013 23:24:24 +0100 Subject: [PATCH] Added ARC support through Nick Lockwood's ARC Helper; README updated; bumped version to 0.8.1 --- ARCHelper/ARCHelper.h | 59 +++++++++++++++++++++++++ GETTING_STARTED.md | 24 +++++++--- Objective-Zip.xcodeproj/project.pbxproj | 11 +++++ Objective-Zip/FileInZipInfo.h | 3 +- Objective-Zip/FileInZipInfo.m | 9 ++-- Objective-Zip/ZipException.h | 3 +- Objective-Zip/ZipException.m | 2 +- Objective-Zip/ZipFile.h | 3 +- Objective-Zip/ZipFile.m | 7 +-- Objective-Zip/ZipReadStream.h | 3 +- Objective-Zip/ZipReadStream.m | 2 +- Objective-Zip/ZipWriteStream.h | 3 +- Objective-Zip/ZipWriteStream.m | 2 +- README.md | 21 ++++++++- 14 files changed, 130 insertions(+), 22 deletions(-) create mode 100644 ARCHelper/ARCHelper.h diff --git a/ARCHelper/ARCHelper.h b/ARCHelper/ARCHelper.h new file mode 100644 index 0000000..492b012 --- /dev/null +++ b/ARCHelper/ARCHelper.h @@ -0,0 +1,59 @@ +// +// ARC Helper +// +// Version 2.1 +// +// Created by Nick Lockwood on 05/01/2012. +// Copyright 2012 Charcoal Design +// +// Distributed under the permissive zlib license +// Get the latest version from here: +// +// https://gist.github.com/1563325 +// + +#ifndef ah_retain +#if __has_feature(objc_arc) +#define ah_retain self +#define ah_dealloc self +#define release self +#define autorelease self +#else +#define ah_retain retain +#define ah_dealloc dealloc +#define __bridge +#endif +#endif + +// Weak reference support + +#import +#if (!__has_feature(objc_arc)) || \ +(defined __IPHONE_OS_VERSION_MIN_REQUIRED && \ +__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0) || \ +(defined __MAC_OS_X_VERSION_MIN_REQUIRED && \ +__MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7) +#undef weak +#define weak unsafe_unretained +#undef __weak +#define __weak __unsafe_unretained +#endif + +// Weak delegate support + +#ifndef ah_weak +#import +#if (__has_feature(objc_arc)) && \ +((defined __IPHONE_OS_VERSION_MIN_REQUIRED && \ +__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0) || \ +(defined __MAC_OS_X_VERSION_MIN_REQUIRED && \ +__MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_7)) +#define ah_weak weak +#define __ah_weak __weak +#else +#define ah_weak unsafe_unretained +#define __ah_weak __unsafe_unretained +#endif +#endif + +// ARC Helper ends diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index d0e0cdc..c1639ca 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -1,4 +1,5 @@ + Getting started with Objective-Zip ================================== @@ -6,19 +7,23 @@ Objective-Zip exposes basic functionalities to read and write zip files, encapsulating both ZLib for the compression mechanism and MiniZip for the zip wrapping. + Adding Objective-Zip to your project ------------------------------------ The library is distributed as source only, so simply download the unit test application and copy-paste these directories in your own project: -- ZLib, -- MiniZip, -- Objective-Zip. + +- ARCHelper +- ZLib +- MiniZip +- Objective-Zip The first two are simply copies of the distribution of version 1.2.7 of ZLib and of version 1.1 of MiniZip (which is itself part of ZLib contributions), while the third is their Objective-C wrapper. + Main concepts ------------- @@ -35,6 +40,7 @@ is a read-only modality. You can not request reading operations on a write-mode zip file, nor request writing operations on a read-mode zip file. + Adding a file to a zip file --------------------------- @@ -50,6 +56,7 @@ the file, and then must be closed: [stream writeData:abcData]; [stream finishedWriting]; + Reading a file from a zip file ------------------------------ @@ -75,6 +82,7 @@ have been set with a length greater than 0: the readDataWithBuffer API will use that length to know how many bytes it can fetch from the zip file. + Listing files in a zip file --------------------------- @@ -102,8 +110,10 @@ zip and expand it: } Note that the FileInZipInfo class provide two sizes: -- length is the original (uncompressed) file size, while -- size is the compressed file size. + +- **length** is the original (uncompressed) file size, while +- **size** is the compressed file size. + Closing the zip file -------------------- @@ -113,9 +123,11 @@ file corruption problems: [zipFile close]; + Notes ===== + File/folder hierarchy inide the zip ----------------------------------- @@ -126,6 +138,7 @@ extracts the files to consider these file names as expressing a structure and rebuild it on the file system (and viceversa during creation). Common zippers/unzippers simply follow this rule. + Memory management ----------------- @@ -162,6 +175,7 @@ you can do so using a read-then-write buffered loop like this: [read finishedReading]; [buffer release]; + Exception handling ------------------ diff --git a/Objective-Zip.xcodeproj/project.pbxproj b/Objective-Zip.xcodeproj/project.pbxproj index 0242b9a..0c32e61 100755 --- a/Objective-Zip.xcodeproj/project.pbxproj +++ b/Objective-Zip.xcodeproj/project.pbxproj @@ -94,6 +94,7 @@ 8C83F49410E7CBCB002FB3CB /* FileInZipInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FileInZipInfo.m; path = "Objective-Zip/FileInZipInfo.m"; sourceTree = ""; }; 8C8F2D3910EBC94B00F75833 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; }; 8C8F2D9210EBCE0300F75833 /* ObjectiveZipIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ObjectiveZipIcon.png; sourceTree = ""; }; + 8C9893AF16E5511500E1190A /* ARCHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ARCHelper.h; sourceTree = ""; }; 8CBE431610E95FA300AC9ED3 /* ZipReadStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ZipReadStream.h; path = "Objective-Zip/ZipReadStream.h"; sourceTree = ""; }; 8CBE431710E95FA300AC9ED3 /* ZipReadStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ZipReadStream.m; path = "Objective-Zip/ZipReadStream.m"; sourceTree = ""; }; 8CD230B1159DA6DC00603D19 /* gzclose.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = gzclose.c; path = ZLib/gzclose.c; sourceTree = ""; }; @@ -145,6 +146,7 @@ 8C6D353B10E56BA400B63EFA /* Objective-Zip */, 8C6D350110E56A4B00B63EFA /* MiniZip */, 8C6D350010E56A4500B63EFA /* ZLib */, + 8C9893AE16E550E600E1190A /* ARC Helper */, 080E96DDFE201D6D7F000001 /* Classes */, 29B97315FDCFA39411CA2CEA /* Other Sources */, 29B97317FDCFA39411CA2CEA /* Resources */, @@ -251,6 +253,15 @@ name = "Objective-Zip"; sourceTree = ""; }; + 8C9893AE16E550E600E1190A /* ARC Helper */ = { + isa = PBXGroup; + children = ( + 8C9893AF16E5511500E1190A /* ARCHelper.h */, + ); + name = "ARC Helper"; + path = ARCHelper; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ diff --git a/Objective-Zip/FileInZipInfo.h b/Objective-Zip/FileInZipInfo.h index 06097f5..231d89b 100644 --- a/Objective-Zip/FileInZipInfo.h +++ b/Objective-Zip/FileInZipInfo.h @@ -1,6 +1,6 @@ // // FileInZipInfo.h -// Objective-Zip v. 0.8 +// Objective-Zip v. 0.8.1 // // Created by Gianluca Bertani on 27/12/09. // Copyright 2009-10 Flying Dolphin Studio. All rights reserved. @@ -33,6 +33,7 @@ #import #import "ZipFile.h" +#import "ARCHelper.h" @interface FileInZipInfo : NSObject { diff --git a/Objective-Zip/FileInZipInfo.m b/Objective-Zip/FileInZipInfo.m index ee8d9f0..4fa2ad8 100644 --- a/Objective-Zip/FileInZipInfo.m +++ b/Objective-Zip/FileInZipInfo.m @@ -1,6 +1,6 @@ // // FileInZipInfo.m -// Objective-Zip v. 0.8 +// Objective-Zip v. 0.8.1 // // Created by Gianluca Bertani on 27/12/09. // Copyright 2009-10 Flying Dolphin Studio. All rights reserved. @@ -38,12 +38,12 @@ - (id) initWithName:(NSString *)name length:(NSUInteger)length level:(ZipCompressionLevel)level crypted:(BOOL)crypted size:(NSUInteger)size date:(NSDate *)date crc32:(NSUInteger)crc32 { if (self= [super init]) { - _name= [name retain]; + _name= [name ah_retain]; _length= length; _level= level; _crypted= crypted; _size= size; - _date= [date retain]; + _date= [date ah_retain]; _crc32= crc32; } @@ -53,7 +53,8 @@ - (void) dealloc { [_date release]; [_name release]; - [super dealloc]; + + [super ah_dealloc]; } @synthesize name= _name; diff --git a/Objective-Zip/ZipException.h b/Objective-Zip/ZipException.h index dbb21b4..d8ace90 100644 --- a/Objective-Zip/ZipException.h +++ b/Objective-Zip/ZipException.h @@ -1,6 +1,6 @@ // // ZipException.h -// Objective-Zip v. 0.8 +// Objective-Zip v. 0.8.1 // // Created by Gianluca Bertani on 25/12/09. // Copyright 2009-10 Flying Dolphin Studio. All rights reserved. @@ -32,6 +32,7 @@ // #import +#import "ARCHelper.h" @interface ZipException : NSException { diff --git a/Objective-Zip/ZipException.m b/Objective-Zip/ZipException.m index d437cfb..9d260f0 100644 --- a/Objective-Zip/ZipException.m +++ b/Objective-Zip/ZipException.m @@ -1,6 +1,6 @@ // // ZipException.m -// Objective-Zip v. 0.8 +// Objective-Zip v. 0.8.1 // // Created by Gianluca Bertani on 25/12/09. // Copyright 2009-10 Flying Dolphin Studio. All rights reserved. diff --git a/Objective-Zip/ZipFile.h b/Objective-Zip/ZipFile.h index a2ac3e3..ef2d49f 100644 --- a/Objective-Zip/ZipFile.h +++ b/Objective-Zip/ZipFile.h @@ -1,6 +1,6 @@ // // ZipFile.h -// Objective-Zip v.0.8 +// Objective-Zip v.0.8.1 // // Created by Gianluca Bertani on 25/12/09. // Copyright 2009-10 Flying Dolphin Studio. All rights reserved. @@ -32,6 +32,7 @@ // #import +#import "ARCHelper.h" #include "zip.h" #include "unzip.h" diff --git a/Objective-Zip/ZipFile.m b/Objective-Zip/ZipFile.m index fb45b1e..078fdb6 100644 --- a/Objective-Zip/ZipFile.m +++ b/Objective-Zip/ZipFile.m @@ -1,6 +1,6 @@ // // ZipFile.m -// Objective-Zip v. 0.8 +// Objective-Zip v. 0.8.1 // // Created by Gianluca Bertani on 25/12/09. // Copyright 2009-10 Flying Dolphin Studio. All rights reserved. @@ -45,7 +45,7 @@ - (id) initWithFileName:(NSString *)fileName mode:(ZipFileMode)mode { if (self= [super init]) { - _fileName= [fileName retain]; + _fileName= [fileName ah_retain]; _mode= mode; switch (mode) { @@ -85,7 +85,8 @@ - (void) dealloc { [_fileName release]; - [super dealloc]; + + [super ah_dealloc]; } - (ZipWriteStream *) writeFileInZipWithName:(NSString *)fileNameInZip compressionLevel:(ZipCompressionLevel)compressionLevel { diff --git a/Objective-Zip/ZipReadStream.h b/Objective-Zip/ZipReadStream.h index 1de1b6e..36315ff 100644 --- a/Objective-Zip/ZipReadStream.h +++ b/Objective-Zip/ZipReadStream.h @@ -1,6 +1,6 @@ // // ZipReadStream.h -// Objective-Zip v. 0.8 +// Objective-Zip v. 0.8.1 // // Created by Gianluca Bertani on 28/12/09. // Copyright 2009-10 Flying Dolphin Studio. All rights reserved. @@ -32,6 +32,7 @@ // #import +#import "ARCHelper.h" #include "unzip.h" diff --git a/Objective-Zip/ZipReadStream.m b/Objective-Zip/ZipReadStream.m index 9f69c05..bf660ab 100644 --- a/Objective-Zip/ZipReadStream.m +++ b/Objective-Zip/ZipReadStream.m @@ -1,6 +1,6 @@ // // ZipReadStream.m -// Objective-Zip v. 0.8 +// Objective-Zip v. 0.8.1 // // Created by Gianluca Bertani on 28/12/09. // Copyright 2009-10 Flying Dolphin Studio. All rights reserved. diff --git a/Objective-Zip/ZipWriteStream.h b/Objective-Zip/ZipWriteStream.h index ab6b0c4..66e3931 100644 --- a/Objective-Zip/ZipWriteStream.h +++ b/Objective-Zip/ZipWriteStream.h @@ -1,6 +1,6 @@ // // ZipWriteStream.h -// Objective-Zip v. 0.8 +// Objective-Zip v. 0.8.1 // // Created by Gianluca Bertani on 25/12/09. // Copyright 2009-10 Flying Dolphin Studio. All rights reserved. @@ -32,6 +32,7 @@ // #import +#import "ARCHelper.h" #include "zip.h" diff --git a/Objective-Zip/ZipWriteStream.m b/Objective-Zip/ZipWriteStream.m index 7ec0529..29b7679 100644 --- a/Objective-Zip/ZipWriteStream.m +++ b/Objective-Zip/ZipWriteStream.m @@ -1,6 +1,6 @@ // // ZipWriteStream.m -// Objective-Zip v. 0.8 +// Objective-Zip v. 0.8.1 // // Created by Gianluca Bertani on 25/12/09. // Copyright 2009-10 Flying Dolphin Studio. All rights reserved. diff --git a/README.md b/README.md index 7e08f79..869f9d1 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,23 @@ + Objective-Zip ============= + Introduction ------------ Objective-Zip is a small Objective-C library that wraps ZLib and MiniZip in an object-oriented friendly way. + What is contained here ---------------------- The source repository contains a sample application with full sources for ZLib, MiniZip and Objective-Zip, together with a unit test UI. The versions included are: + - 1.2.7 for ZLib; - 1.1 for MiniZip; - latest version for Objective-Zip. @@ -24,41 +28,54 @@ respective authors and redistributed on respect of their software license. Please refer to their websites (linked above) for more informations. + Getting started --------------- -Please see GETTING_STARTED. +Please see **GETTING_STARTED.md**. + License ------- The library is distributed under the New BSD License. + Version history --------------- +Version 0.8.1: + +- Added support for ARC through Nick Lockwood's [ARC Helper](https://gist.github.com/1563325) + Version 0.8: + - Updated ZLip to 1.2.7 - Updated MiniZip to 1.1 - Added method to get file name from a ZipFile instance Version 0.7.3: + - Fixed memory leak in test app Version 0.7.2: + - Added variant of writeFileInZipWithName that accepts also a file date - Fixed bug with date handling Version 0.7.1: + - Fixed a bug in creation of an encrypted zip file Version 0.7.0: + - Initial public beta release + Compatibility ------------- -Version 0.8 has been tested with iOS from 4.2 to 5.1, but should be +Version 0.8.1 has been tested with iOS from 4.2 to 6.1, but should be compatible with earlier versions too. Le me know of any issues that should arise.