Index: src/OFTarArchive.h ================================================================== --- src/OFTarArchive.h +++ src/OFTarArchive.h @@ -27,11 +27,11 @@ * * @brief A class for accessing and manipulating tar archives. */ @interface OFTarArchive: OFObject { - OFStream *_stream; + OF_KINDOF(OFStream *) _stream; enum { OF_TAR_ARCHIVE_MODE_READ, OF_TAR_ARCHIVE_MODE_WRITE, OF_TAR_ARCHIVE_MODE_APPEND } _mode; @@ -40,17 +40,17 @@ /*! * @brief Creates a new OFTarArchive object with the specified stream. * * @param stream A stream from which the tar archive will be read. - * For append mode, this needs to be a seekable stream. + * For append mode, this needs to be an OFSeekableStream. * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFTarArchive */ -+ (instancetype)archiveWithStream: (OFStream *)stream ++ (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode; #ifdef OF_HAVE_FILES /*! * @brief Creates a new OFTarArchive object with the specified file. @@ -68,17 +68,17 @@ /*! * @brief Initializes an already allocated OFTarArchive object with the * specified stream. * * @param stream A stream from which the tar archive will be read. - * For append mode, this needs to be a seekable stream. + * For append mode, this needs to be an OFSeekableStream. * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFTarArchive */ -- initWithStream: (OFStream *)stream +- initWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; #ifdef OF_HAVE_FILES /*! * @brief Initializes an already allocated OFTarArchive object with the Index: src/OFTarArchive.m ================================================================== --- src/OFTarArchive.m +++ src/OFTarArchive.m @@ -71,11 +71,11 @@ for (size_t i = UTF8StringLength; i < length; i++) buffer[i] = '\0'; } @implementation OFTarArchive: OFObject -+ (instancetype)archiveWithStream: (OFStream *)stream ++ (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } @@ -87,11 +87,11 @@ return [[[self alloc] initWithPath: path mode: mode] autorelease]; } #endif -- initWithStream: (OFStream *)stream +- initWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode { self = [super init]; @try { @@ -114,12 +114,12 @@ bool empty = true; if (![_stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; - [(OFSeekableStream *)stream seekToOffset: -1024 - whence: SEEK_END]; + [stream seekToOffset: -1024 + whence: SEEK_END]; [stream readIntoBuffer: buffer.c exactLength: 1024]; for (size_t i = 0; i < 1024 / sizeof(uint32_t); i++) if (buffer.u32[i] != 0) @@ -126,12 +126,12 @@ empty = false; if (!empty) @throw [OFInvalidFormatException exception]; - [(OFSeekableStream *)stream seekToOffset: -1024 - whence: SEEK_END]; + [stream seekToOffset: -1024 + whence: SEEK_END]; } } @catch (id e) { [self release]; @throw e; } Index: src/OFZIPArchive.h ================================================================== --- src/OFZIPArchive.h +++ src/OFZIPArchive.h @@ -21,21 +21,20 @@ OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); -@class OFSeekableStream; @class OFStream; /*! * @class OFZIPArchive OFZIPArchive.h ObjFW/OFZIPArchive.h * * @brief A class for accessing and manipulating ZIP files. */ @interface OFZIPArchive: OFObject { - OFSeekableStream *_stream; + OF_KINDOF(OFStream *) _stream; enum { OF_ZIP_ARCHIVE_MODE_READ, OF_ZIP_ARCHIVE_MODE_WRITE, OF_ZIP_ARCHIVE_MODE_APPEND } _mode; @@ -54,20 +53,21 @@ * The archive comment. */ @property (readonly, nonatomic) OFString *archiveComment; /*! - * @brief Creates a new OFZIPArchive object with the specified seekable stream. + * @brief Creates a new OFZIPArchive object with the specified stream. * - * @param stream A seekable stream from which the ZIP archive will be read + * @param stream A stream from which the ZIP archive will be read. + * For read and append mode, this needs to be an OFSeekableStream. * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFZIPArchive */ -+ (instancetype)archiveWithSeekableStream: (OFSeekableStream *)stream - mode: (OFString *)mode; ++ (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream + mode: (OFString *)mode; #ifdef OF_HAVE_FILES /*! * @brief Creates a new OFZIPArchive object with the specified file. * @@ -83,20 +83,21 @@ - init OF_UNAVAILABLE; /*! * @brief Initializes an already allocated OFZIPArchive object with the - * specified seekable stream. + * specified stream. * - * @param stream A seekable stream from which the ZIP archive will be read + * @param stream A stream from which the ZIP archive will be read. + * For read and append mode, this needs to be an OFSeekableStream. * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFZIPArchive */ -- initWithSeekableStream: (OFSeekableStream *)stream - mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; +- initWithStream: (OF_KINDOF(OFStream *))stream + mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; #ifdef OF_HAVE_FILES /*! * @brief Initializes an already allocated OFZIPArchive object with the * specified file. Index: src/OFZIPArchive.m ================================================================== --- src/OFZIPArchive.m +++ src/OFZIPArchive.m @@ -22,10 +22,11 @@ #import "OFZIPArchiveEntry.h" #import "OFZIPArchiveEntry+Private.h" #import "OFData.h" #import "OFArray.h" #import "OFDictionary.h" +#import "OFStream.h" #import "OFSeekableStream.h" #ifdef OF_HAVE_FILES # import "OFFile.h" #endif #import "OFInflateStream.h" @@ -134,15 +135,15 @@ } @implementation OFZIPArchive @synthesize archiveComment = _archiveComment; -+ (instancetype)archiveWithSeekableStream: (OFSeekableStream *)stream - mode: (OFString *)mode ++ (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream + mode: (OFString *)mode { - return [[[self alloc] initWithSeekableStream: stream - mode: mode] autorelease]; + return [[[self alloc] initWithStream: stream + mode: mode] autorelease]; } #ifdef OF_HAVE_FILES + (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode @@ -155,19 +156,22 @@ - init { OF_INVALID_INIT_METHOD } -- initWithSeekableStream: (OFSeekableStream *)stream - mode: (OFString *)mode +- initWithStream: (OF_KINDOF(OFStream *))stream + mode: (OFString *)mode { self = [super init]; @try { _stream = [stream retain]; if ([mode isEqual: @"r"]) { + if (![stream isKindOfClass: [OFSeekableStream class]]) + @throw [OFInvalidArgumentException exception]; + _mode = OF_ZIP_ARCHIVE_MODE_READ; [self of_readZIPInfo]; [self of_readEntries]; } else if ([mode isEqual: @"w"] || [mode isEqual: @"a"]) @@ -189,12 +193,12 @@ mode: (OFString *)mode { OFFile *file = [[OFFile alloc] initWithPath: path mode: mode]; @try { - self = [self initWithSeekableStream: file - mode: mode]; + self = [self initWithStream: file + mode: mode]; } @finally { [file release]; } return self; Index: utils/ofzip/ZIPArchive.m ================================================================== --- utils/ofzip/ZIPArchive.m +++ utils/ofzip/ZIPArchive.m @@ -67,12 +67,12 @@ mode: (OFString *)mode { self = [super init]; @try { - _archive = [[OFZIPArchive alloc] initWithSeekableStream: stream - mode: mode]; + _archive = [[OFZIPArchive alloc] initWithStream: stream + mode: mode]; } @catch (id e) { [self release]; @throw e; }