@@ -18,21 +18,19 @@ #include #import "OFZIPArchive.h" #import "OFZIPArchiveEntry.h" #import "OFZIPArchiveEntry+Private.h" +#import "OFArray.h" #import "OFCRC32.h" #import "OFData.h" -#import "OFArray.h" #import "OFDictionary.h" -#import "OFStream.h" +#import "OFInflate64Stream.h" +#import "OFInflateStream.h" #import "OFSeekableStream.h" -#ifdef OF_HAVE_FILES -# import "OFFile.h" -#endif -#import "OFInflateStream.h" -#import "OFInflate64Stream.h" +#import "OFStream.h" +#import "OFURLHandler.h" #import "OFChecksumMismatchException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" @@ -162,16 +160,14 @@ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } -#ifdef OF_HAVE_FILES -+ (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode ++ (instancetype)archiveWithURL: (OFURL *)URL mode: (OFString *)mode { - return [[[self alloc] initWithPath: path mode: mode] autorelease]; + return [[[self alloc] initWithURL: URL mode: mode] autorelease]; } -#endif - (instancetype)init { OF_INVALID_INIT_METHOD } @@ -221,29 +217,31 @@ } return self; } -#ifdef OF_HAVE_FILES -- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode -{ - OFFile *file; - - if ([mode isEqual: @"a"]) - file = [[OFFile alloc] initWithPath: path mode: @"r+"]; - else - file = [[OFFile alloc] initWithPath: path mode: mode]; +- (instancetype)initWithURL: (OFURL *)URL mode: (OFString *)mode +{ + void *pool = objc_autoreleasePoolPush(); + OFStream *stream; @try { - self = [self initWithStream: file mode: mode]; - } @finally { - [file release]; + if ([mode isEqual: @"a"]) + stream = [OFURLHandler openItemAtURL: URL mode: @"r+"]; + else + stream = [OFURLHandler openItemAtURL: URL mode: mode]; + } @catch (id e) { + [self release]; + @throw e; } + + self = [self initWithStream: stream mode: mode]; + + objc_autoreleasePoolPop(pool); return self; } -#endif - (void)dealloc { if (_stream != nil) [self close];