Index: src/OFGZIPStream.h ================================================================== --- src/OFGZIPStream.h +++ src/OFGZIPStream.h @@ -82,22 +82,28 @@ /*! * @brief Creates a new OFGZIPStream with the specified underlying stream. * * @param stream The underlying stream for the OFGZIPStream + * @param mode The mode for the OFGZIPStream. Valid modes are "r" for reading + * and "w" for writing. * @return A new, autoreleased OFGZIPStream */ -+ (instancetype)streamWithStream: (OFStream *)stream; ++ (instancetype)streamWithStream: (OFStream *)stream + mode: (OFString *)mode; - init OF_UNAVAILABLE; /*! * @brief Initializes an already allocated OFGZIPStream with the specified * underlying stream. * * @param stream The underlying stream for the OFGZIPStream + * @param mode The mode for the OFGZIPStream. Valid modes are "r" for reading + * and "w" for writing. * @return An initialized OFGZIPStream */ -- initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER; +- initWithStream: (OFStream *)stream + mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END Index: src/OFGZIPStream.m ================================================================== --- src/OFGZIPStream.m +++ src/OFGZIPStream.m @@ -22,29 +22,38 @@ #import "crc32.h" #import "OFChecksumFailedException.h" #import "OFInvalidFormatException.h" +#import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFTruncatedDataException.h" @implementation OFGZIPStream + (instancetype)streamWithStream: (OFStream *)stream + mode: (OFString *)mode { - return [[[self alloc] initWithStream: stream] autorelease]; + return [[[self alloc] initWithStream: stream + mode: mode] autorelease]; } - init { OF_INVALID_INIT_METHOD } - initWithStream: (OFStream *)stream + mode: (OFString *)mode { self = [super init]; @try { + if (![mode isEqual: @"r"]) + @throw [OFNotImplementedException + exceptionWithSelector: _cmd + object: self]; + _stream = [stream retain]; _CRC32 = ~0; } @catch (id e) { [self release]; @throw e; Index: src/OFZIPArchive.m ================================================================== --- src/OFZIPArchive.m +++ src/OFZIPArchive.m @@ -168,11 +168,15 @@ if ([mode isEqual: @"r"]) { _mode = OF_ZIP_ARCHIVE_MODE_READ; [self of_readZIPInfo]; [self of_readEntries]; - } else + } else if ([mode isEqual: @"w"] || [mode isEqual: @"a"]) + @throw [OFNotImplementedException + exceptionWithSelector: _cmd + object: self]; + else @throw [OFInvalidArgumentException exception]; } @catch (id e) { [self release]; @throw e; } Index: utils/ofzip/GZIPArchive.m ================================================================== --- utils/ofzip/GZIPArchive.m +++ utils/ofzip/GZIPArchive.m @@ -53,11 +53,12 @@ - initWithStream: (OF_KINDOF(OFStream *))stream { self = [super init]; @try { - _stream = [[OFGZIPStream alloc] initWithStream: stream]; + _stream = [[OFGZIPStream alloc] initWithStream: stream + mode: @"r"]; } @catch (id e) { [self release]; @throw e; } Index: utils/ofzip/OFZIP.m ================================================================== --- utils/ofzip/OFZIP.m +++ utils/ofzip/OFZIP.m @@ -347,11 +347,12 @@ archive = [GZIPArchive archiveWithStream: file]; else if ([type isEqual: @"tar"]) archive = [TarArchive archiveWithStream: file]; else if ([type isEqual: @"tgz"]) archive = [TarArchive archiveWithStream: - [OFGZIPStream streamWithStream: file]]; + [OFGZIPStream streamWithStream: file + mode: @"r"]]; else if ([type isEqual: @"zip"]) archive = [ZIPArchive archiveWithStream: file]; else { [of_stderr writeLine: OF_LOCALIZED( @"unknown_archive_type",