16 Commits
1.0.1 ... 1.0.3

Author SHA1 Message Date
Gianluca Bertani
04d8d9d1d4 Fixed podspec by adding public headers 2016-08-28 12:12:38 +02:00
Gianluca Bertani
cc40af1311 Bumped version to 1.0.3 2016-08-28 11:28:16 +02:00
Gianluca Bertani
1dbde8f9c9 Bumped version to 1.0.3 2016-08-28 11:26:08 +02:00
Gianluca Bertani
5a90a66267 Merge pull request #41 from atlasti/master
Removing a potential leak found by static analysis.
2016-08-28 11:01:55 +02:00
Gianluca Bertani
00386a3fe9 Merge pull request #48 from andyj-at-aspin/Swift3ExceptionThrowing
Changed throwing of Swift errors
2016-08-28 10:59:34 +02:00
Andy Johnson
ec6056de67 Changed throwing of Swift errors from the Stream reading/writing to be nonnull_error rather than zero_result. Continues to work with Swift 2.x but now works with Swift 3 Beta (circa XCode 8 beta 6) 2016-08-26 16:53:19 +01:00
Martin Winter
2485f97586 Apply changes from commit e54e129 of https://github.com/madler/zlib/ repository to silence compiler warning about shifting a negative signed value. 2016-04-01 13:57:52 +01:00
Gianluca Bertani
8364f87f9a Merge pull request #44 from deni2s/master
Update README.md
2016-03-18 08:37:38 +01:00
deni2s
9dfa7e43da Update README.md
Suppresses warning about using int type instead of long long for info.size
2016-03-17 17:38:39 +02:00
Gianluca Bertani
401dfa4b17 Merge pull request #43 from deni2s/patch-1
Update README.md
2016-03-17 16:21:54 +01:00
deni2s
a1e5810879 Update README.md
Fixed typo in example code
2016-03-17 17:07:48 +02:00
Kevin Meaney
64185c4750 Removing a potential leek found by static analysis. 2016-01-04 11:22:31 +00:00
Gianluca Bertani
4ed48f8e04 Bumped version to 1.0.2 2015-10-18 14:37:22 +02:00
Gianluca Bertani
6797222f63 Improved section on reading a file; removed section on memory management; added version 1.0.2 in version history 2015-10-18 14:33:49 +02:00
Gianluca Bertani
f1f4fee67f Improved interface of locateFileInZip and readDataWithBuffer in NSError variant 2015-10-18 14:32:45 +02:00
Gianluca Bertani
07288c8e00 Fixed pod name in README 2015-10-18 10:35:30 +02:00
31 changed files with 178 additions and 125 deletions

View File

@@ -342,7 +342,10 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f
return 0;
if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
{
TRYFREE(buf);
return 0;
}
file_size = ZTELL64(*pzlib_filefunc_def, filestream);

View File

@@ -575,7 +575,10 @@ local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f
return 0;
if (ZSEEK64(*pzlib_filefunc_def, filestream, 0, ZLIB_FILEFUNC_SEEK_END) != 0)
{
TRYFREE(buf);
return 0;
}
file_size = ZTELL64(*pzlib_filefunc_def, filestream);

View File

@@ -140,12 +140,7 @@ class Objective_Zip_Swift_Tests: XCTestCase {
NSLog("Test 1: reading from first file's stream...")
let data1 = NSMutableData(length:256)!
var error : NSError?
let bytesRead1 = read1.readDataWithBuffer(data1, error:&error)
if error != nil {
throw error!
}
let bytesRead1 = try read1.readDataWithBuffer(data1)
XCTAssertEqual(3, bytesRead1)
@@ -167,11 +162,7 @@ class Objective_Zip_Swift_Tests: XCTestCase {
NSLog("Test 1: reading from second file's stream...")
let data2 = NSMutableData(length:256)!
let bytesRead2 = read2.readDataWithBuffer(data2, error:&error)
if error != nil {
throw error!
}
let bytesRead2 = try read2.readDataWithBuffer(data2)
XCTAssertEqual(3, bytesRead2)
@@ -201,11 +192,11 @@ class Objective_Zip_Swift_Tests: XCTestCase {
}
}
/*
* Uncomment to execute this test, but be careful: takes 5 minutes and consumes 5 GB of disk space
*
func test02ZipAndUnzip5GB() {
// TODO Remove to enable this test, but be careful: takes 5 minutes and consumes 5 GB of disk space
return
let documentsUrl = NSURL(fileURLWithPath:NSHomeDirectory(), isDirectory:true).URLByAppendingPathComponent("Documents")
let fileUrl = documentsUrl.URLByAppendingPathComponent("huge_test.zip")
let filePath = fileUrl.path!
@@ -286,13 +277,9 @@ class Objective_Zip_Swift_Tests: XCTestCase {
NSLog("Test 2: reading from file's stream...")
for (var i = 0; i < HUGE_TEST_NUMBER_OF_BLOCKS; i++) {
var error : NSError?
let bytesRead = read.readDataWithBuffer(buffer, error:&error)
if error != nil {
throw error!
}
let bytesRead = try read.readDataWithBuffer(buffer)
XCTAssertEqual(UInt(data.length), bytesRead)
XCTAssertEqual(data.length, bytesRead)
let range = buffer.rangeOfData(checkData, options:NSDataSearchOptions(), range:NSMakeRange(0, buffer.length))
@@ -319,6 +306,7 @@ class Objective_Zip_Swift_Tests: XCTestCase {
XCTFail("Error caught: \(error.code) - \(error.userInfo[NSLocalizedFailureReasonErrorKey])")
}
}
*/
func test03UnzipMacZipFile() -> () {
let documentsUrl = NSURL(fileURLWithPath:NSHomeDirectory(), isDirectory:true).URLByAppendingPathComponent("Documents")
@@ -355,12 +343,7 @@ class Objective_Zip_Swift_Tests: XCTestCase {
NSLog("Test 3: reading from file's stream...")
let buffer = NSMutableData(length:1024)!
var error : NSError?
let bytesRead = read.readDataWithBuffer(buffer, error:&error)
if error != nil {
throw error!
}
let bytesRead = try read.readDataWithBuffer(buffer)
let fileText = NSString(bytes:buffer.bytes, length:Int(bytesRead), encoding:NSUTF8StringEncoding)
@@ -418,12 +401,7 @@ class Objective_Zip_Swift_Tests: XCTestCase {
NSLog("Test 4: reading from file's stream...")
let buffer = NSMutableData(length:1024)!
var error : NSError?
let bytesRead = read.readDataWithBuffer(buffer, error:&error)
if error != nil {
throw error!
}
let bytesRead = try read.readDataWithBuffer(buffer)
let fileText = NSString(bytes:buffer.bytes, length:Int(bytesRead), encoding:NSUTF8StringEncoding)

View File

@@ -208,11 +208,11 @@
}
}
/*
* Uncomment to execute this test, but be careful: takes 5 minutes and consumes 5 GB of disk space
*
- (void) test02ZipAndUnzip5GB {
// TODO Remove to enable this test, but be careful: takes 5 minutes and consumes 5 GB of disk space
return;
NSString *documentsDir= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *filePath= [documentsDir stringByAppendingPathComponent:@"huge_test.zip"];
@@ -319,6 +319,7 @@
[[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL];
}
}
*/
- (void) test03UnzipMacZipFile {
NSString *documentsDir= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

View File

@@ -1,6 +1,6 @@
//
// OZFileInZipInfo+Internals.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZFileInZipInfo.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 27/12/09.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZFileInZipInfo.m
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 27/12/09.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZZipCompressionLevel.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZZipException+Internals.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZZipException.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 25/12/09.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZZipException.m
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 25/12/09.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZZipFile+NSError.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 09/09/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
@@ -34,6 +34,17 @@
#import "OZZipFile.h"
/**
@brief Indicates the file could not be located in the zip file.
*/
static const NSInteger OZLocateFileResultNotFound= -1;
/**
@brief Indicates the file has been successfully located in the zip file.
*/
static const NSInteger OZLocateFileResultFound= 1;
@interface OZZipFile (NSError)
@@ -211,13 +222,16 @@
<code>readCurrentFileInZip</code>.</p>
@param error If passed, may be filled with an NSError is case the file can't
be located.
@return <code>YES</code> if the file has been located and selected,
<code>NO</code> if the specified file name is not present in the zip file or
the file could not be located due to an error.
@return <code>OZLocateFileResultFound</code> if the file has been located
and selected, <code>OZLocateFileResultNotFound</code> if the specified
file name is not present in the zip file, or <code>0</code> if the file could
not be located due to an error.
<br/>NOTE: return value convention is different in the standard (non-NSError
compliant) interface.
@throws OZZipException If the zip file has been opened with a mode other than
Unzip.
*/
- (BOOL) locateFileInZip:(nonnull NSString *)fileNameInZip error:(NSError * __autoreleasing __nullable * __nullable)error;
- (NSInteger) __attribute__((swift_error(nonnull_error))) locateFileInZip:(nonnull NSString *)fileNameInZip error:(NSError * __autoreleasing __nullable * __nullable)error;
/**
@brief Returns the number of files contained in the zip file.
@@ -228,7 +242,7 @@
@throws OZZipException If the zip file has been opened with a mode other
than Unzip.
*/
- (NSUInteger) numFilesInZipWithError:(NSError * __autoreleasing __nullable * __nullable)error;
- (NSUInteger) __attribute__((swift_error(nonnull_error))) numFilesInZipWithError:(NSError * __autoreleasing __nullable * __nullable)error;
/**
@brief Returns a list of OZFileInZipInfo with the information on all the files

View File

@@ -1,6 +1,6 @@
//
// OZZipFile+Standard.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 09/09/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
@@ -199,6 +199,8 @@
<code>readCurrentFileInZip</code>.</p>
@return <code>YES</code> if the file has been located and selected,
<code>NO</code> if the specified file name is not present in the zip file.
<br/>NOTE: return value convention is different in NSError compliant
interface.
@throws OZZipException If the file can't be located due to an error or if the
zip file has been opened with a mode other than Unzip.
*/

View File

@@ -1,6 +1,6 @@
//
// OZZipFile.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 25/12/09.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZZipFile.m
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 25/12/09.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
@@ -444,12 +444,13 @@
} ERROR_WRAP_END_AND_RETURN(error, NO);
}
- (BOOL) locateFileInZip:(NSString *)fileNameInZip error:(NSError * __autoreleasing *)error {
- (NSInteger) locateFileInZip:(NSString *)fileNameInZip error:(NSError * __autoreleasing *)error {
ERROR_WRAP_BEGIN {
return [self locateFileInZip:fileNameInZip];
BOOL located= [self locateFileInZip:fileNameInZip];
return (located ? OZLocateFileResultFound : OZLocateFileResultNotFound);
} ERROR_WRAP_END_AND_RETURN(error, NO);
} ERROR_WRAP_END_AND_RETURN(error, 0);
}
- (NSUInteger) numFilesInZipWithError:(NSError * __autoreleasing *)error {

View File

@@ -1,6 +1,6 @@
//
// OZZipFileMode.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZZipReadStream+Internals.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZZipReadStream+NSError.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 09/09/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
@@ -34,6 +34,12 @@
#import "OZZipReadStream.h"
/**
@brief Indicates the end of the file has been reached.
*/
static const NSInteger OZReadStreamResultEndOfFile= -1;
@interface OZZipReadStream (NSError)
@@ -46,10 +52,13 @@
@param buffer The buffer where read and uncompressed data must be stored.
@param error If passed, may be filled with an NSError is case data could
not be read.
@return The number of uncompressed bytes read, <code>0</code> if the end of
the file has been reached or data could not be read due to an error.
@return The number of uncompressed bytes read, <code>OZReadStreamResultEndOfFile</code>
if the end of the file has been reached, or <code>0</code>
if data could not be read due to an error.
<br/>NOTE: return value convention is different in the standard (non-NSError
compliant) interface.
*/
- (NSUInteger) readDataWithBuffer:(nonnull NSMutableData *)buffer error:(NSError * __autoreleasing __nullable * __nullable)error;
- (NSInteger) __attribute__((swift_error(nonnull_error))) readDataWithBuffer:(nonnull NSMutableData *)buffer error:(NSError * __autoreleasing __nullable * __nullable)error;
/**
@brief Closes the read steam.

View File

@@ -1,6 +1,6 @@
//
// OZZipReadStream+Standard.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 09/09/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
@@ -46,6 +46,8 @@
@param buffer The buffer where read and uncompressed data must be stored.
@return The number of uncompressed bytes read, <code>0</code> if the end of
the file has been reached.
<br/>NOTE: return value convention is different in NSError compliant
interface.
@throws OZZipException If the data could not be read due to an error.
*/
- (NSUInteger) readDataWithBuffer:(nonnull NSMutableData *)buffer;

View File

@@ -1,6 +1,6 @@
//
// OZZipReadStream.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 28/12/09.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZZipReadStream.m
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 28/12/09.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
@@ -93,10 +93,11 @@
#pragma mark -
#pragma mark Reading data (NSError variants)
- (NSUInteger) readDataWithBuffer:(NSMutableData *)buffer error:(NSError * __autoreleasing *)error {
- (NSInteger) readDataWithBuffer:(NSMutableData *)buffer error:(NSError * __autoreleasing *)error {
ERROR_WRAP_BEGIN {
return [self readDataWithBuffer:buffer];
NSUInteger bytesRead= [self readDataWithBuffer:buffer];
return (bytesRead == 0) ? OZReadStreamResultEndOfFile : bytesRead;
} ERROR_WRAP_END_AND_RETURN(error, 0);
}

View File

@@ -1,6 +1,6 @@
//
// OZZipWriteStream+Internals.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZZipWriteStream+NSError.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 09/09/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.
@@ -47,6 +47,8 @@
@param data The data to be compressed and written.
@param error If passed, may be filled with an NSError is case data could
not be written.
@return <code>YES</code> if data has been written, <code>NO</code> if
data could not be written due to an error.
*/
- (BOOL) writeData:(nonnull NSData *)data error:(NSError * __autoreleasing __nullable * __nullable)error;

View File

@@ -1,6 +1,6 @@
//
// OZZipWriteStream+Standard.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 09/09/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZZipWriteStream.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 25/12/09.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// OZZipWriteStream.m
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 25/12/09.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// Objective-Zip+NSError.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 09/09/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

View File

@@ -1,6 +1,6 @@
//
// Objective-Zip.h
// Objective-Zip v. 1.0.1
// Objective-Zip v. 1.0.3
//
// Created by Gianluca Bertani on 27/08/15.
// Copyright 2009-2015 Gianluca Bertani. All rights reserved.

124
README.md
View File

@@ -42,7 +42,7 @@ Adding Objective-Zip to your project
The library is distributed via CocoaPods, you can add a dependency in you pod
file with the following line:
pod 'Objective-Zip', '~> 1.0'
pod 'objective-zip', '~> 1.0'
You can then access Objective-Zip classes with the following import
statement if you plan to use exception handling:
@@ -105,7 +105,10 @@ The OZZipFile class, when used in unzip mode, must be treated like a
cursor: you position the instance on a file at a time, either by
step-forwarding or by locating the file by name. Once you are on the
correct file, you can obtain an instance of a OZZipReadStream that will
let you read the content (and then must be closed):
let you read the content (and then must be closed).
Since the file may not fit into memory, you can read it block by block using
a buffer:
```objective-c
OZZipFile *unzipFile= [[OZZipFile alloc] initWithFileName:@"test.zip"
@@ -114,14 +117,50 @@ OZZipFile *unzipFile= [[OZZipFile alloc] initWithFileName:@"test.zip"
[unzipFile goToFirstFileInZip];
OZZipReadStream *read= [unzipFile readCurrentFileInZip];
NSMutableData *data= [[NSMutableData alloc] initWithLength:256];
int bytesRead= [read readDataWithBuffer:data];
NSMutableData *data= [[NSMutableData alloc] initWithLength:BUFFER_SIZE];
do {
// Reset buffer length
[buffer setLength:BUFFER_SIZE];
// Read bytes and check for end of file
int bytesRead= [read readDataWithBuffer:data];
if (bytesRead <= 0)
break;
[buffer setLength:bytesRead];
// Do something with buffer
} while (YES);
[read finishedReading];
```
Alternatively, if you know in advance the file will fit into memory, you may
preallocate a buffer big enough and read the all file at once. In the example
below the buffer is preallocated with precisely the uncompressed size of the
file:
```objective-c
OZZipFile *unzipFile= [[OZZipFile alloc] initWithFileName:@"test.zip"
mode:OZZipFileModeUnzip];
[unzipFile goToFirstFileInZip];
OZFileInZipInfo *info= [unzipFile getCurrentFileInZipInfo];
OZZipReadStream *read= [unzipFile readCurrentFileInZip];
NSMutableData *data= [[NSMutableData alloc] initWithLength:info.length];
[read readDataWithBuffer:data];
// Do something with data
[read finishedReading];
```
Note that the NSMutableData instance that acts as the read buffer must
have been set with a length greater than 0: the readDataWithBuffer API
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.
@@ -136,19 +175,18 @@ zip and expand it:
```objective-c
OZZipFile *unzipFile= [[OZZipFile alloc] initWithFileName:@"test.zip"
mode:ZipFileModeUnzip];
mode:OZZipFileModeUnzip];
NSArray *infos= [unzipFile listFileInZipInfos];
for (OZFileInZipInfo *info in infos) {
NSLog(@"- %@ %@ %d (%d)", info.name, info.date, info.size,
info.level);
NSLog(@"- %@ %@ %llu (%d)", info.name, info.date, info.size, info.level);
// Locate the file in the zip
[unzipFile locateFileInZip:info.name];
// Expand the file in memory
OZZipReadStream *read= [unzipFile readCurrentFileInZip];
NSMutableData *data= [[NSMutableData alloc] initWithLength:256];
NSMutableData *data= [[NSMutableData alloc] initWithLength:info.length];
int bytesRead= [read readDataWithBuffer:data];
[read finishedReading];
}
@@ -182,45 +220,6 @@ rebuild it on the file system (and viceversa during creation). Common
zippers/unzippers simply follow this rule.
Memory management
-----------------
If you need to extract huge files that cannot be contained in memory,
you can do so using a read-then-write buffered loop like this:
```objective-c
NSFileHandle *file= [NSFileHandle fileHandleForWritingAtPath:filePath];
NSMutableData *buffer= [[NSMutableData alloc]
initWithLength:BUFFER_SIZE];
OZZipReadStream *read= [unzipFile readCurrentFileInZip];
// Read-then-write buffered loop
do {
// Reset buffer length
[buffer setLength:BUFFER_SIZE];
// Expand next chunk of bytes
int bytesRead= [read readDataWithBuffer:buffer];
if (bytesRead > 0) {
// Write what we have read
[buffer setLength:bytesRead];
[file writeData:buffer];
} else
break;
} while (YES);
// Clean up
[file closeFile];
[read finishedReading];
[buffer release];
```
Error handling
--------------
@@ -255,6 +254,21 @@ Apple's NSError pattern is of course mandatory with Swift programming
language, since it does not support exception handling.
Differences in the interface
----------------------------
Note that a few minor differences exist in the standard interface vs. the
NSError pattern interface. Specifically:
* `[OZZipFile locateFileInZip:error:]` returns a `NSInteger` in place of a
`BOOL`. Here the special values `OZLocateFileResultNotFound` and
`OZLocateFileResultNotFound`, respectively `1` and `-1`, are used in place of
`YES` and `NO`, since `0` is reserved for the case where an error occurred.
* `[OZZipReadStream readDataWithBuffer:error:]` similarly returns a
`NSInteger` in place of a `NSUInteger`. Here the special value
`OZReadStreamResultEndOfFile`, corresponding to `-1`, is used for the
end-of-file case, since `0` is again reserved for error occurrence.
License
=======
@@ -265,6 +279,18 @@ The library is distributed under the New BSD License.
Version history
===============
Version 1.0.3:
- Fixed some memory leaks in MiniZip (contributed by @SheffieldKevin)
- Silenced a warning about shifting a negative value in ZLib (contributed by Martin Winter)
- Fixed throwing of errors so that it is compatible with Swift 3 (contributed by @andyj-at-aspin)
- Fixed typos and errors in README (contributed by @deni2s)
Version 1.0.2:
- Fixed interface for `locateFileInZip` and `readDataWithBuffer` in NSError
version so that they correctly support Swift error handling.
Version 1.0.1:
- Fixed compatibility bugs with Swift
@@ -331,7 +357,7 @@ Version 0.7.0:
Compatibility
=============
Version 1.0.1 has been tested with iOS up to 9.0 and OS X up to 10.10.5, but
Version 1.0.3 has been tested with iOS up to 9.3 and OS X up to 10.11, but
should be compatible with earlier versions too, down to iOS 5.1 and OS X 10.7.
Le me know of any issues that should arise.

View File

@@ -1504,9 +1504,10 @@ z_streamp strm;
{
struct inflate_state FAR *state;
if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
if (strm == Z_NULL || strm->state == Z_NULL)
return (long)(((unsigned long)0 - 1) << 16);
state = (struct inflate_state FAR *)strm->state;
return ((long)(state->back) << 16) +
return (long)(((unsigned long)((long)state->back)) << 16) +
(state->mode == COPY ? state->length :
(state->mode == MATCH ? state->was - state->length : 0));
}

View File

@@ -3,7 +3,7 @@ Pod::Spec.new do |s|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.name = "objective-zip"
s.version = "1.0.1"
s.version = "1.0.3"
s.summary = "An object-oriented friendly wrapper library for ZLib and MiniZip, in Objective-C for iOS and OS X"
s.description = <<-DESC
@@ -48,6 +48,16 @@ Pod::Spec.new do |s|
s.source_files = "Objective-Zip/**/*.{h,m}", "MiniZip/**/*.{h,c}", "ZLib/**/*.{h,c}"
# ――― Publich Headers ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.public_header_files = ["Objective-Zip/OZZipFile.h", "Objective-Zip/OZZipFile+Standard.h", "Objective-Zip/OZZipFile+NSError.h",
"Objective-Zip/OZZipFileMode.h", "Objective-Zip/OZZipCompressionLevel.h", "Objective-Zip/OZZipException.h",
"Objective-Zip/OZZipWriteStream.h", "Objective-Zip/OZZipWriteStream+Standard.h",
"Objective-Zip/OZZipWriteStream+NSError.h", "Objective-Zip/OZZipReadStream.h",
"Objective-Zip/OZZipReadStream+Standard.h", "Objective-Zip/OZZipReadStream+NSError.h",
"Objective-Zip/OZFileInZipInfo.h", "Objective-Zip/Objective-Zip.h", "Objective-Zip/Objective-Zip+NSError.h"]
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.requires_arc = true