Some code clean up

This commit is contained in:
Gianluca Bertani
2015-08-27 17:18:43 +02:00
parent 5cbe4cde4d
commit 48a53904d8
19 changed files with 595 additions and 124 deletions
+1 -5
View File
@@ -32,11 +32,7 @@
//
#import "Objective_ZipViewController.h"
#import "../Objective-Zip/OZZipFile.h"
#import "../Objective-Zip/OZZipException.h"
#import "../Objective-Zip/OZFileInZipInfo.h"
#import "../Objective-Zip/OZZipWriteStream.h"
#import "../Objective-Zip/OZZipReadStream.h"
#import "Objective-Zip.h"
#define HUGE_TEST_BLOCK_LENGTH (50000)
#define HUGE_TEST_NUMBER_OF_BLOCKS (100000)
+14
View File
@@ -82,6 +82,13 @@
8C8F2D9210EBCE0300F75833 /* ObjectiveZipIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ObjectiveZipIcon.png; sourceTree = "<group>"; };
8CBE431610E95FA300AC9ED3 /* OZZipReadStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OZZipReadStream.h; path = "Objective-Zip/OZZipReadStream.h"; sourceTree = "<group>"; };
8CBE431710E95FA300AC9ED3 /* OZZipReadStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OZZipReadStream.m; path = "Objective-Zip/OZZipReadStream.m"; sourceTree = "<group>"; };
8CC6A7931B8F5B360062D97E /* Objective-Zip.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "Objective-Zip.h"; path = "Objective-Zip/Objective-Zip.h"; sourceTree = "<group>"; };
8CC6A7941B8F5C370062D97E /* OZZipFileMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = OZZipFileMode.h; path = "Objective-Zip/OZZipFileMode.h"; sourceTree = "<group>"; };
8CC6A7951B8F5C810062D97E /* OZZipCompressionLevel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = OZZipCompressionLevel.h; path = "Objective-Zip/OZZipCompressionLevel.h"; sourceTree = "<group>"; };
8CC6A7961B8F5F570062D97E /* OZZipException+Internals.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "OZZipException+Internals.h"; path = "Objective-Zip/OZZipException+Internals.h"; sourceTree = "<group>"; };
8CC6A7971B8F5F780062D97E /* OZZipWriteStream+Internals.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "OZZipWriteStream+Internals.h"; path = "Objective-Zip/OZZipWriteStream+Internals.h"; sourceTree = "<group>"; };
8CC6A7981B8F5F950062D97E /* OZFileInZipInfo+Internals.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "OZFileInZipInfo+Internals.h"; path = "Objective-Zip/OZFileInZipInfo+Internals.h"; sourceTree = "<group>"; };
8CC6A7991B8F5FB40062D97E /* OZZipReadStream+Internals.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "OZZipReadStream+Internals.h"; path = "Objective-Zip/OZZipReadStream+Internals.h"; sourceTree = "<group>"; };
8CD8B3E917766067005212EC /* adler32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = adler32.c; path = ZLib/adler32.c; sourceTree = "<group>"; };
8CD8B3EA17766067005212EC /* compress.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = compress.c; path = ZLib/compress.c; sourceTree = "<group>"; };
8CD8B3EB17766067005212EC /* crc32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = crc32.c; path = ZLib/crc32.c; sourceTree = "<group>"; };
@@ -215,15 +222,22 @@
8C6D353B10E56BA400B63EFA /* Objective-Zip */ = {
isa = PBXGroup;
children = (
8CC6A7931B8F5B360062D97E /* Objective-Zip.h */,
8C6D353E10E56BD300B63EFA /* OZZipFile.h */,
8C6D353F10E56BD300B63EFA /* OZZipFile.m */,
8CC6A7941B8F5C370062D97E /* OZZipFileMode.h */,
8CC6A7951B8F5C810062D97E /* OZZipCompressionLevel.h */,
8C6D356910E56F4D00B63EFA /* OZZipException.h */,
8CC6A7961B8F5F570062D97E /* OZZipException+Internals.h */,
8C6D356A10E56F4D00B63EFA /* OZZipException.m */,
8C6D357410E5797600B63EFA /* OZZipWriteStream.h */,
8CC6A7971B8F5F780062D97E /* OZZipWriteStream+Internals.h */,
8C6D357510E5797600B63EFA /* OZZipWriteStream.m */,
8C83F49310E7CBCB002FB3CB /* OZFileInZipInfo.h */,
8CC6A7981B8F5F950062D97E /* OZFileInZipInfo+Internals.h */,
8C83F49410E7CBCB002FB3CB /* OZFileInZipInfo.m */,
8CBE431610E95FA300AC9ED3 /* OZZipReadStream.h */,
8CC6A7991B8F5FB40062D97E /* OZZipReadStream+Internals.h */,
8CBE431710E95FA300AC9ED3 /* OZZipReadStream.m */,
);
name = "Objective-Zip";
+46
View File
@@ -0,0 +1,46 @@
//
// OZFileInZipInfo+Internals.h
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of Gianluca Bertani nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#import "OZFileInZipInfo.h"
@interface OZFileInZipInfo (Internals)
#pragma mark -
#pragma mark Initialization
- (instancetype) initWithName:(NSString *)name length:(NSUInteger)length level:(OZZipCompressionLevel)level crypted:(BOOL)crypted size:(NSUInteger)size date:(NSDate *)date crc32:(NSUInteger)crc32;
@end
+6 -14
View File
@@ -3,7 +3,7 @@
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 27/12/09.
// Copyright 2009-10 Flying Dolphin Studio. All rights reserved.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -33,22 +33,13 @@
#import <Foundation/Foundation.h>
#import "OZZipFile.h"
#import "OZZipCompressionLevel.h"
@interface OZFileInZipInfo : NSObject {
@private
NSUInteger _length;
OZZipCompressionLevel _level;
BOOL _crypted;
NSUInteger _size;
NSDate *_date;
NSUInteger _crc32;
NSString *_name;
}
@interface OZFileInZipInfo : NSObject
- (id) initWithName:(NSString *)name length:(NSUInteger)length level:(OZZipCompressionLevel)level crypted:(BOOL)crypted size:(NSUInteger)size date:(NSDate *)date crc32:(NSUInteger)crc32;
#pragma mark -
#pragma mark Properties
@property (nonatomic, readonly) NSString *name;
@property (nonatomic, readonly) NSUInteger length;
@@ -58,4 +49,5 @@
@property (nonatomic, readonly) NSDate *date;
@property (nonatomic, readonly) NSUInteger crc32;
@end
+32 -2
View File
@@ -3,7 +3,7 @@
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 27/12/09.
// Copyright 2009-10 Flying Dolphin Studio. All rights reserved.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -34,9 +34,35 @@
#import "OZFileInZipInfo.h"
#pragma mark -
#pragma mark OZFileInZipInfo extension
@interface OZFileInZipInfo () {
@private
NSUInteger _length;
OZZipCompressionLevel _level;
BOOL _crypted;
NSUInteger _size;
NSDate *_date;
NSUInteger _crc32;
NSString *_name;
}
@end
#pragma mark -
#pragma mark OZFileInZipInfo implementation
@implementation OZFileInZipInfo
- (id) initWithName:(NSString *)name length:(NSUInteger)length level:(OZZipCompressionLevel)level crypted:(BOOL)crypted size:(NSUInteger)size date:(NSDate *)date crc32:(NSUInteger)crc32 {
#pragma mark -
#pragma mark Initialization
- (instancetype) initWithName:(NSString *)name length:(NSUInteger)length level:(OZZipCompressionLevel)level crypted:(BOOL)crypted size:(NSUInteger)size date:(NSDate *)date crc32:(NSUInteger)crc32 {
if (self= [super init]) {
_name= name;
_length= length;
@@ -51,6 +77,9 @@
}
#pragma mark -
#pragma mark Properties
@synthesize name= _name;
@synthesize length= _length;
@synthesize level= _level;
@@ -59,4 +88,5 @@
@synthesize date= _date;
@synthesize crc32= _crc32;
@end
+46
View File
@@ -0,0 +1,46 @@
//
// OZZipCompressionLevel.h
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of Gianluca Bertani nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef Objective_Zip_OZZipCompressionLevel_h
#define Objective_Zip_OZZipCompressionLevel_h
typedef enum {
OZZipCompressionLevelDefault= -1,
OZZipCompressionLevelNone= 0,
OZZipCompressionLevelFastest= 1,
OZZipCompressionLevelBest= 9
} OZZipCompressionLevel;
#endif
+46
View File
@@ -0,0 +1,46 @@
//
// OZZipException+Internals.h
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of Gianluca Bertani nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#import "OZZipException.h"
@interface OZZipException (Internals)
#pragma mark -
#pragma mark Initialization
- (instancetype) initWithReason:(NSString *)reason;
- (instancetype) initWithError:(NSInteger)error reason:(NSString *)reason;
@end
+6 -8
View File
@@ -3,7 +3,7 @@
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 25/12/09.
// Copyright 2009-10 Flying Dolphin Studio. All rights reserved.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -34,15 +34,13 @@
#import <Foundation/Foundation.h>
@interface OZZipException : NSException {
@private
NSInteger _error;
}
@interface OZZipException : NSException
- (id) initWithReason:(NSString *)reason;
- (id) initWithError:(NSInteger)error reason:(NSString *)reason;
#pragma mark -
#pragma mark Properties
@property (nonatomic, readonly) NSInteger error;
@end
+28 -3
View File
@@ -3,7 +3,7 @@
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 25/12/09.
// Copyright 2009-10 Flying Dolphin Studio. All rights reserved.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -34,9 +34,29 @@
#import "OZZipException.h"
#pragma mark -
#pragma mark OZZipException extension
@interface OZZipException () {
@private
NSInteger _error;
}
@end
#pragma mark -
#pragma mark OZZipException implementation
@implementation OZZipException
- (id) initWithReason:(NSString *)reason {
#pragma mark -
#pragma mark Initialization
- (instancetype) initWithReason:(NSString *)reason {
if (self= [super initWithName:@"OZZipException" reason:reason userInfo:nil]) {
_error= 0;
}
@@ -44,7 +64,7 @@
return self;
}
- (id) initWithError:(NSInteger)error reason:(NSString *)reason {
- (instancetype) initWithError:(NSInteger)error reason:(NSString *)reason {
if (self= [super initWithName:@"OZZipException" reason:reason userInfo:nil]) {
_error= error;
}
@@ -52,6 +72,11 @@
return self;
}
#pragma mark -
#pragma mark Properties
@synthesize error= _error;
@end
+32 -27
View File
@@ -3,7 +3,7 @@
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 25/12/09.
// Copyright 2009-10 Flying Dolphin Studio. All rights reserved.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -33,55 +33,60 @@
#import <Foundation/Foundation.h>
#include "zip.h"
#include "unzip.h"
#import "OZZipFileMode.h"
#import "OZZipCompressionLevel.h"
typedef enum {
OZZipFileModeUnzip,
OZZipFileModeCreate,
OZZipFileModeAppend
} OZZipFileMode;
typedef enum {
OZZipCompressionLevelDefault= -1,
OZZipCompressionLevelNone= 0,
OZZipCompressionLevelFastest= 1,
OZZipCompressionLevelBest= 9
} OZZipCompressionLevel;
@class OZZipReadStream;
@class OZZipWriteStream;
@class OZFileInZipInfo;
@interface OZZipFile : NSObject {
NSString *_fileName;
OZZipFileMode _mode;
@interface OZZipFile : NSObject
@private
zipFile _zipFile;
unzFile _unzFile;
}
- (id) initWithFileName:(NSString *)fileName mode:(OZZipFileMode)mode;
#pragma mark -
#pragma mark Initialization
- (instancetype) initWithFileName:(NSString *)fileName mode:(OZZipFileMode)mode;
#pragma mark -
#pragma mark File writing
- (OZZipWriteStream *) writeFileInZipWithName:(NSString *)fileNameInZip compressionLevel:(OZZipCompressionLevel)compressionLevel;
- (OZZipWriteStream *) writeFileInZipWithName:(NSString *)fileNameInZip fileDate:(NSDate *)fileDate compressionLevel:(OZZipCompressionLevel)compressionLevel;
- (OZZipWriteStream *) writeFileInZipWithName:(NSString *)fileNameInZip fileDate:(NSDate *)fileDate compressionLevel:(OZZipCompressionLevel)compressionLevel password:(NSString *)password crc32:(NSUInteger)crc32;
- (NSString*) fileName;
- (NSUInteger) numFilesInZip;
- (NSArray *) listFileInZipInfos;
#pragma mark -
#pragma mark File seeking and info
- (void) goToFirstFileInZip;
- (BOOL) goToNextFileInZip;
- (BOOL) locateFileInZip:(NSString *)fileNameInZip;
- (NSArray *) listFileInZipInfos;
- (OZFileInZipInfo *) getCurrentFileInZipInfo;
#pragma mark -
#pragma mark File reading
- (OZZipReadStream *) readCurrentFileInZip;
- (OZZipReadStream *) readCurrentFileInZipWithPassword:(NSString *)password;
#pragma mark -
#pragma mark Closing
- (void) close;
#pragma mark -
#pragma mark Properties
@property (nonatomic, readonly) NSString *fileName;
@property (nonatomic, readonly) NSUInteger numFilesInZip;
@end
+91 -39
View File
@@ -3,7 +3,7 @@
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 25/12/09.
// Copyright 2009-10 Flying Dolphin Studio. All rights reserved.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -33,17 +33,46 @@
#import "OZZipFile.h"
#import "OZZipException.h"
#import "OZZipException+Internals.h"
#import "OZZipReadStream.h"
#import "OZZipReadStream+Internals.h"
#import "OZZipWriteStream.h"
#import "OZZipWriteStream+Internals.h"
#import "OZFileInZipInfo.h"
#import "OZFileInZipInfo+Internals.h"
#include "zip.h"
#include "unzip.h"
#define FILE_IN_ZIP_MAX_NAME_LENGTH (256)
#pragma mark -
#pragma mark OZZipFile extension
@interface OZZipFile () {
NSString *_fileName;
OZZipFileMode _mode;
@private
zipFile _zipFile;
unzFile _unzFile;
}
@end
#pragma mark -
#pragma mark OZZipFile implementation
@implementation OZZipFile
- (id) initWithFileName:(NSString *)fileName mode:(OZZipFileMode)mode {
#pragma mark -
#pragma mark Initialization
- (instancetype) initWithFileName:(NSString *)fileName mode:(OZZipFileMode)mode {
if (self= [super init]) {
_fileName= fileName;
_mode= mode;
@@ -84,6 +113,9 @@
}
#pragma mark -
#pragma mark File writing
- (OZZipWriteStream *) writeFileInZipWithName:(NSString *)fileNameInZip compressionLevel:(OZZipCompressionLevel)compressionLevel {
if (_mode == OZZipFileModeUnzip) {
NSString *reason= [NSString stringWithFormat:@"Operation not permitted with Unzip mode"];
@@ -193,44 +225,9 @@
return [[OZZipWriteStream alloc] initWithZipFileStruct:_zipFile fileNameInZip:fileNameInZip];
}
- (NSString*) fileName {
return _fileName;
}
- (NSUInteger) numFilesInZip {
if (_mode != OZZipFileModeUnzip) {
NSString *reason= [NSString stringWithFormat:@"Operation not permitted without Unzip mode"];
@throw [[OZZipException alloc] initWithReason:reason];
}
unz_global_info64 gi;
int err= unzGetGlobalInfo64(_unzFile, &gi);
if (err != UNZ_OK) {
NSString *reason= [NSString stringWithFormat:@"Error getting global info in '%@'", _fileName];
@throw [[OZZipException alloc] initWithError:err reason:reason];
}
return gi.number_entry;
}
- (NSArray *) listFileInZipInfos {
int num= [self numFilesInZip];
if (num < 1)
return [[NSArray alloc] init];
NSMutableArray *files= [[NSMutableArray alloc] initWithCapacity:num];
[self goToFirstFileInZip];
for (int i= 0; i < num; i++) {
OZFileInZipInfo *info= [self getCurrentFileInZipInfo];
[files addObject:info];
if ((i +1) < num)
[self goToNextFileInZip];
}
return files;
}
#pragma mark -
#pragma mark File seeking and info
- (void) goToFirstFileInZip {
if (_mode != OZZipFileModeUnzip) {
@@ -281,6 +278,25 @@
return YES;
}
- (NSArray *) listFileInZipInfos {
int num= [self numFilesInZip];
if (num < 1)
return [[NSArray alloc] init];
NSMutableArray *files= [[NSMutableArray alloc] initWithCapacity:num];
[self goToFirstFileInZip];
for (int i= 0; i < num; i++) {
OZFileInZipInfo *info= [self getCurrentFileInZipInfo];
[files addObject:info];
if ((i +1) < num)
[self goToNextFileInZip];
}
return files;
}
- (OZFileInZipInfo *) getCurrentFileInZipInfo {
if (_mode != OZZipFileModeUnzip) {
NSString *reason= [NSString stringWithFormat:@"Operation not permitted without Unzip mode"];
@@ -331,6 +347,10 @@
return info;
}
#pragma mark -
#pragma mark File reading
- (OZZipReadStream *) readCurrentFileInZip {
if (_mode != OZZipFileModeUnzip) {
NSString *reason= [NSString stringWithFormat:@"Operation not permitted without Unzip mode"];
@@ -383,6 +403,10 @@
return [[OZZipReadStream alloc] initWithUnzFileStruct:_unzFile fileNameInZip:fileNameInZip];
}
#pragma mark -
#pragma mark Closing
- (void) close {
switch (_mode) {
case OZZipFileModeUnzip: {
@@ -420,4 +444,32 @@
}
#pragma mark -
#pragma mark Properties
@dynamic fileName;
- (NSString*) fileName {
return _fileName;
}
@dynamic numFilesInZip;
- (NSUInteger) numFilesInZip {
if (_mode != OZZipFileModeUnzip) {
NSString *reason= [NSString stringWithFormat:@"Operation not permitted without Unzip mode"];
@throw [[OZZipException alloc] initWithReason:reason];
}
unz_global_info64 gi;
int err= unzGetGlobalInfo64(_unzFile, &gi);
if (err != UNZ_OK) {
NSString *reason= [NSString stringWithFormat:@"Error getting global info in '%@'", _fileName];
@throw [[OZZipException alloc] initWithError:err reason:reason];
}
return gi.number_entry;
}
@end
+45
View File
@@ -0,0 +1,45 @@
//
// OZZipFileMode.h
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of Gianluca Bertani nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef Objective_Zip_OZZipFileMode_h
#define Objective_Zip_OZZipFileMode_h
typedef enum {
OZZipFileModeUnzip,
OZZipFileModeCreate,
OZZipFileModeAppend
} OZZipFileMode;
#endif
+48
View File
@@ -0,0 +1,48 @@
//
// OZZipReadStream+Internals.h
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of Gianluca Bertani nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#import "OZZipReadStream.h"
#include "unzip.h"
@interface OZZipReadStream (Internals)
#pragma mark -
#pragma mark Initialization
- (instancetype) initWithUnzFileStruct:(unzFile)unzFile fileNameInZip:(NSString *)fileNameInZip;
@end
+6 -10
View File
@@ -3,7 +3,7 @@
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 28/12/09.
// Copyright 2009-10 Flying Dolphin Studio. All rights reserved.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -33,19 +33,15 @@
#import <Foundation/Foundation.h>
#include "unzip.h"
@interface OZZipReadStream : NSObject
@interface OZZipReadStream : NSObject {
NSString *_fileNameInZip;
@private
unzFile _unzFile;
}
- (id) initWithUnzFileStruct:(unzFile)unzFile fileNameInZip:(NSString *)fileNameInZip;
#pragma mark -
#pragma mark Reading data
- (NSUInteger) readDataWithBuffer:(NSMutableData *)buffer;
- (void) finishedReading;
@end
+27 -3
View File
@@ -3,7 +3,7 @@
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 28/12/09.
// Copyright 2009-10 Flying Dolphin Studio. All rights reserved.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -32,15 +32,35 @@
//
#import "OZZipReadStream.h"
#import "OZZipReadStream+Internals.h"
#import "OZZipException.h"
#import "OZZipException+Internals.h"
#include "unzip.h"
#pragma mark -
#pragma mark OZZipReadStream extension
@interface OZZipReadStream () {
NSString *_fileNameInZip;
@private
unzFile _unzFile;
}
@end
#pragma mark -
#pragma mark OZZipReadStream implementation
@implementation OZZipReadStream
- (id) initWithUnzFileStruct:(unzFile)unzFile fileNameInZip:(NSString *)fileNameInZip {
#pragma mark -
#pragma mark Initialization
- (instancetype) initWithUnzFileStruct:(unzFile)unzFile fileNameInZip:(NSString *)fileNameInZip {
if (self= [super init]) {
_unzFile= unzFile;
_fileNameInZip= fileNameInZip;
@@ -49,6 +69,10 @@
return self;
}
#pragma mark -
#pragma mark Reading data
- (NSUInteger) readDataWithBuffer:(NSMutableData *)buffer {
int err= unzReadCurrentFile(_unzFile, [buffer mutableBytes], [buffer length]);
if (err < 0) {
@@ -0,0 +1,48 @@
//
// OZZipWriteStream+Internals.h
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of Gianluca Bertani nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#import "OZZipWriteStream.h"
#include "zip.h"
@interface OZZipWriteStream (Internals)
#pragma mark -
#pragma mark Initialization
- (instancetype) initWithZipFileStruct:(zipFile)zipFile fileNameInZip:(NSString *)fileNameInZip;
@end
+6 -10
View File
@@ -3,7 +3,7 @@
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 25/12/09.
// Copyright 2009-10 Flying Dolphin Studio. All rights reserved.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -33,19 +33,15 @@
#import <Foundation/Foundation.h>
#include "zip.h"
@interface OZZipWriteStream : NSObject
@interface OZZipWriteStream : NSObject {
NSString *_fileNameInZip;
@private
zipFile _zipFile;
}
- (id) initWithZipFileStruct:(zipFile)zipFile fileNameInZip:(NSString *)fileNameInZip;
#pragma mark -
#pragma mark Writing data
- (void) writeData:(NSData *)data;
- (void) finishedWriting;
@end
+27 -3
View File
@@ -3,7 +3,7 @@
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 25/12/09.
// Copyright 2009-10 Flying Dolphin Studio. All rights reserved.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -32,15 +32,35 @@
//
#import "OZZipWriteStream.h"
#import "OZZipWriteStream+Internals.h"
#import "OZZipException.h"
#import "OZZipException+Internals.h"
#include "zip.h"
#pragma mark -
#pragma mark OZZipWriteStream extension
@interface OZZipWriteStream () {
NSString *_fileNameInZip;
@private
zipFile _zipFile;
}
@end
#pragma mark -
#pragma mark OZZipWriteStream implementation
@implementation OZZipWriteStream
- (id) initWithZipFileStruct:(zipFile)zipFile fileNameInZip:(NSString *)fileNameInZip {
#pragma mark -
#pragma mark Initialization
- (instancetype) initWithZipFileStruct:(zipFile)zipFile fileNameInZip:(NSString *)fileNameInZip {
if (self= [super init]) {
_zipFile= zipFile;
_fileNameInZip= fileNameInZip;
@@ -49,6 +69,10 @@
return self;
}
#pragma mark -
#pragma mark Writing data
- (void) writeData:(NSData *)data {
int err= zipWriteInFileInZip(_zipFile, [data bytes], [data length]);
if (err < 0) {
+40
View File
@@ -0,0 +1,40 @@
//
// Objective-Zip.h
// Objective-Zip v. 0.8.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of Gianluca Bertani nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#import "OZZipFile.h"
#import "OZZipFileMode.h"
#import "OZZipCompressionLevel.h"
#import "OZZipException.h"
#import "OZZipWriteStream.h"
#import "OZZipReadStream.h"
#import "OZFileInZipInfo.h"