@@ -31,17 +31,24 @@ */ OF_SUBCLASSING_RESTRICTED @interface OFZIPArchive: OFObject { OFStream *_stream; +#ifdef OF_ZIP_ARCHIVE_M +@public +#endif int64_t _offset; +@protected uint_least8_t _mode; uint32_t _diskNumber, _centralDirectoryDisk; uint64_t _centralDirectoryEntriesInDisk, _centralDirectoryEntries; uint64_t _centralDirectorySize; int64_t _centralDirectoryOffset; OFString *_Nullable _archiveComment; +#ifdef OF_ZIP_ARCHIVE_M +@public +#endif OFMutableArray OF_GENERIC(OFZIPArchiveEntry *) *_entries; OFMutableDictionary OF_GENERIC(OFString *, OFZIPArchiveEntry *) *_pathToEntryMap; OFStream *_Nullable _lastReturnedStream; } @@ -69,25 +76,36 @@ * 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 + * @throw OFInvalidFormatException The format is not that of a valid ZIP archive */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; -#ifdef OF_HAVE_FILES /** * @brief Creates a new OFZIPArchive object with the specified file. * - * @param path The path to the ZIP file + * @param URI The URI to the ZIP file * @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 + * @throw OFInvalidFormatException The format is not that of a valid ZIP archive + */ ++ (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode; + +/** + * @brief Creates a URI for accessing a the specified file within the specified + * ZIP archive. + * + * @param path The path of the file within the archive + * @param URI The URI of the archive + * @return A URI for accessing the specified file within the specified ZIP + * archive */ -+ (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode; -#endif ++ (OFURI *)URIForFilePath: (OFString *)path inArchiveWithURI: (OFURI *)URI; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFZIPArchive object with the @@ -97,27 +115,27 @@ * 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 + * @throw OFInvalidFormatException The format is not that of a valid ZIP archive */ - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; -#ifdef OF_HAVE_FILES /** * @brief Initializes an already allocated OFZIPArchive object with the * specified file. * - * @param path The path to the ZIP file + * @param URI The URI to the ZIP file * @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 + * @throw OFInvalidFormatException The format is not that of a valid ZIP archive */ -- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode; -#endif +- (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode; /** * @brief Returns a stream for reading the specified file from the archive. * * @note This method is only available in read mode. @@ -131,10 +149,18 @@ * invalidated stream will throw an @ref OFReadFailedException or * @ref OFWriteFailedException! * * @param path The path to the file inside the archive * @return A stream for reading the specified file form the archive + * @throw OFNotOpenException The archive is not open + * @throw OFInvalidArgumentException The archive is not in read mode + * @throw OFOpenItemFailedException Opening the specified file within the + * archive failed + * @throw OFInvalidFormatException The local header and the header in the + * central directory do not match enough + * @throw OFUnsupportedVersionException The file uses a version of the ZIP + * format that is not supported */ - (OFStream *)streamForReadingFile: (OFString *)path; /** * @brief Returns a stream for writing the specified entry to the archive. @@ -157,15 +183,25 @@ * * The compressed size. * * The uncompressed size. * * The CRC32. * * Bit 3 and 11 of the general purpose bit flag. * @return A stream for writing the specified entry to the archive + * @throw OFNotOpenException The archive is not open + * @throw OFInvalidArgumentException The archive is not in write mode + * @throw OFOpenItemFailedException Opening the specified file within the + * archive failed. If @ref errNo is `EEXIST`, + * because there is already a file with the + * same name in the archive. + * @throw OFNotImplementedException The desired compression method is not + * implemented */ - (OFStream *)streamForWritingEntry: (OFZIPArchiveEntry *)entry; /** * @brief Closes the OFZIPArchive. + * + * @throw OFNotOpenException The archive is not open */ - (void)close; @end #ifdef __cplusplus