Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from shoby/feature/modern_objective_c_syntax
Browse files Browse the repository at this point in the history
Use modern Objective-C syntax
  • Loading branch information
shoby committed Jan 26, 2016
2 parents 7646b67 + 2d1d683 commit ad9a6e4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 45 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: objective-c
osx_image: xcode7.2

script:
- make clean test
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
PROJECT = DemoApp/DemoApp.xcodeproj
SCHEME = DemoApp
TEST_SDK = iphonesimulator
CONFIGURATION_DEBUG = Debug
PROJECT = 'DemoApp/DemoApp.xcodeproj'
SCHEME = 'DemoApp'
DESTINATION = 'platform=iOS Simulator,name=iPhone 6s'

clean:
xcodebuild \
Expand All @@ -12,6 +11,5 @@ test:
xcodebuild \
-project $(PROJECT) \
-scheme $(SCHEME) \
-sdk $(TEST_SDK) \
-configuration $(CONFIGURATION_DEBUG) \
-destination $(DESTINATION) \
build test
19 changes: 11 additions & 8 deletions SBYZipArchive/SBYZipArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,32 @@

@protocol SBYZipArchiveDelegate;

NS_ASSUME_NONNULL_BEGIN

@interface SBYZipArchive : NSObject
@property (strong, nonatomic, readonly) NSURL *url;
@property (readonly) NSArray *entries;
@property (nonatomic, readonly) NSURL *url;
@property (readonly) NSArray<SBYZipEntry *> *entries;

- (id)initWithContentsOfURL:(NSURL *)url error:(NSError *__autoreleasing *)error;
- (instancetype)initWithContentsOfURL:(NSURL *)url error:(NSError *__autoreleasing *)error;

- (BOOL)loadEntriesWithError:(NSError *__autoreleasing *)error;

- (NSData *)dataForEntry:(SBYZipEntry *)entry error:(NSError *__autoreleasing *)error;

- (void)unzipEntry:(SBYZipEntry *)entry
toURL:(NSURL *)url
success:(void (^)(NSURL *unzippedFileLocation))success
failure:(void (^)(NSError *error))failure
progress:(void (^)(NSUInteger bytesUnzipped, NSUInteger totalBytes))progress;
success:(nullable void (^)(NSURL *unzippedFileLocation))success
failure:(nullable void (^)(NSError *error))failure
progress:(nullable void (^)(NSUInteger bytesUnzipped, NSUInteger totalBytes))progress;
@end


extern NSString* const SBYZipArchiveErrorDomain;

typedef NS_ENUM(NSInteger, SBYZipArchiveError)
{
SBYZipArchiveErrorCannotOpenFile = 1,
SBYZipArchiveErrorCannotGetFileInfo = 2,
SBYZipArchiveErrorCannotUnzipEntryFile = 3,
};
};

NS_ASSUME_NONNULL_END
20 changes: 10 additions & 10 deletions SBYZipArchive/SBYZipArchive.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
static const NSUInteger SBYZipArchiveBufferSize = 4096;

@interface SBYZipArchive () <NSStreamDelegate>
@property (strong, nonatomic, readwrite) NSURL *url;
@property (assign, nonatomic) unzFile unzFile;
@property (strong, nonatomic) NSMutableArray *cachedEntries;
@property (nonatomic, readwrite) NSURL *url;
@property (nonatomic) unzFile unzFile;
@property (nonatomic) NSMutableArray<SBYZipEntry *> *cachedEntries;

@property (strong, nonatomic) dispatch_semaphore_t semaphore;
@property (nonatomic) dispatch_semaphore_t semaphore;

@property (strong, nonatomic) NSOutputStream *outputStream;
@property (strong, nonatomic) NSURL *unzipDestinationURL;
@property (nonatomic) NSOutputStream *outputStream;
@property (nonatomic) NSURL *unzipDestinationURL;

@property (assign, nonatomic) NSUInteger bytesUnzipped;
@property (assign, nonatomic) NSUInteger totalBytes;
@property (nonatomic) NSUInteger bytesUnzipped;
@property (nonatomic) NSUInteger totalBytes;

@property (copy, nonatomic) void (^successBlock)(NSURL *);
@property (copy, nonatomic) void (^failureBlock)(NSError *);
Expand All @@ -33,7 +33,7 @@ @interface SBYZipArchive () <NSStreamDelegate>

@implementation SBYZipArchive

- (id)initWithContentsOfURL:(NSURL *)url error:(NSError *__autoreleasing *)error
- (instancetype)initWithContentsOfURL:(NSURL *)url error:(NSError *__autoreleasing *)error
{
self = [super init];
if (self) {
Expand Down Expand Up @@ -133,7 +133,7 @@ - (BOOL)loadEntriesWithError:(NSError *__autoreleasing *)error
return YES;
}

- (void)unzipEntry:(SBYZipEntry *)entry toURL:(NSURL *)url success:(void (^)(NSURL *))success failure:(void (^)(NSError *))failure progress:(void (^)(NSUInteger, NSUInteger))progress
- (void)unzipEntry:(SBYZipEntry *)entry toURL:(NSURL *)url success:(nullable void (^)(NSURL *))success failure:(nullable void (^)(NSError *))failure progress:(nullable void (^)(NSUInteger, NSUInteger))progress
{
if (!entry) {
return;
Expand Down
26 changes: 15 additions & 11 deletions SBYZipArchive/SBYZipEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@

@class SBYZipArchive;

NS_ASSUME_NONNULL_BEGIN

@interface SBYZipEntry : NSObject
@property (weak, nonatomic, readonly) SBYZipArchive *archive;
@property (copy, nonatomic, readonly) NSString *fileName;
@property (assign, nonatomic, readonly) NSUInteger fileSize;
@property (assign, nonatomic, readonly) NSUInteger offset;
@property (weak, nonatomic, readonly) SBYZipArchive *archive;
@property (copy, nonatomic, readonly) NSString *fileName;
@property (nonatomic, readonly) NSUInteger fileSize;
@property (nonatomic, readonly) NSUInteger offset;

- (id)initWithArchive:(SBYZipArchive *)archive
fileName:(NSString *)fileName
fileSize:(NSUInteger)fileSize
offset:(NSUInteger)offset;
- (instancetype)initWithArchive:(SBYZipArchive *)archive
fileName:(NSString *)fileName
fileSize:(NSUInteger)fileSize
offset:(NSUInteger)offset;

// To unzip small file synchronously
- (NSData *)dataWithError:(NSError *__autoreleasing *)error;

// To unzip large file asynchronously
- (void)unzipToURL:(NSURL *)url
success:(void (^)(NSURL *unzippedFileLocation))success
failure:(void (^)(NSError *error))failure
progress:(void (^)(NSUInteger bytesUnzipped, NSUInteger totalBytes))progress;
success:(nullable void (^)(NSURL *unzippedFileLocation))success
failure:(nullable void (^)(NSError *error))failure
progress:(nullable void (^)(NSUInteger bytesUnzipped, NSUInteger totalBytes))progress;

@end

NS_ASSUME_NONNULL_END
20 changes: 10 additions & 10 deletions SBYZipArchive/SBYZipEntry.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
#import "SBYZipArchive.h"

@interface SBYZipEntry ()
@property (weak, nonatomic, readwrite) SBYZipArchive *archive;
@property (copy, nonatomic, readwrite) NSString *fileName;
@property (assign, nonatomic, readwrite) NSUInteger fileSize;
@property (assign, nonatomic, readwrite) NSUInteger offset;
@property (weak, nonatomic, readwrite) SBYZipArchive *archive;
@property (copy, nonatomic, readwrite) NSString *fileName;
@property (nonatomic, readwrite) NSUInteger fileSize;
@property (nonatomic, readwrite) NSUInteger offset;
@end

@implementation SBYZipEntry

- (id)initWithArchive:(SBYZipArchive *)archive
- (instancetype)initWithArchive:(SBYZipArchive *)archive
fileName:(NSString *)fileName
fileSize:(NSUInteger)fileSize
offset:(NSUInteger)offset
{
self = [super init];
if (self) {
self.archive = archive;
self.fileName = fileName;
self.fileSize = fileSize;
self.offset = offset;
self.archive = archive;
self.fileName = fileName;
self.fileSize = fileSize;
self.offset = offset;
}
return self;
}
Expand All @@ -38,7 +38,7 @@ - (NSData *)dataWithError:(NSError *__autoreleasing *)error
return [self.archive dataForEntry:self error:error];
}

- (void)unzipToURL:(NSURL *)url success:(void (^)(NSURL *))success failure:(void (^)(NSError *))failure progress:(void (^)(NSUInteger, NSUInteger))progress
- (void)unzipToURL:(NSURL *)url success:(nullable void (^)(NSURL *))success failure:(nullable void (^)(NSError *))failure progress:(nullable void (^)(NSUInteger, NSUInteger))progress
{
[self.archive unzipEntry:self toURL:url success:success failure:failure progress:progress];
}
Expand Down

0 comments on commit ad9a6e4

Please sign in to comment.