@@ -15,48 +15,65 @@ */ #import "OFObject.h" #import "OFString.h" -@class OFFile; @class OFArray; @class OFMutableArray; @class OFMutableDictionary; +@class OFSeekableStream; @class OFStream; /*! * @class OFZIPArchive OFZIPArchive.h ObjFW/OFZIPArchive.h * * @brief A class for accessing and manipulating ZIP files. */ @interface OFZIPArchive: OFObject { - OFFile *_file; - OFString *_path; + OFSeekableStream *_stream; uint32_t _diskNumber, _centralDirectoryDisk; uint64_t _centralDirectoryEntriesInDisk, _centralDirectoryEntries; uint64_t _centralDirectorySize, _centralDirectoryOffset; OFString *_archiveComment; OFMutableArray *_entries; OFMutableDictionary *_pathToEntryMap; + OFStream *_lastReturnedStream; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy) OFString *archiveComment; @property (readonly, copy) OFArray *entries; #endif /*! - * @brief Creates a new OFZIPArchive object for the specified file. + * @brief Creates a new OFZIPArchive object with the specified seekable stream. + * + * @param stream A seekable stream from which the ZIP archive will be read + * @return A new, autoreleased OFZIPArchive + */ ++ (instancetype)archiveWithSeekableStream: (OFSeekableStream*)stream; + +/*! + * @brief Creates a new OFZIPArchive object with the specified file. * * @param path The path to the ZIP file * @return A new, autoreleased OFZIPArchive */ + (instancetype)archiveWithPath: (OFString*)path; /*! - * @brief Initializes an already allocated OFZIPArchive object for the + * @brief Initializes an already allocated OFZIPArchive object with the + * specified seekable stream. + * + * @param stream A seekable stream from which the ZIP archive will be read + * @return An initialized OFZIPArchive + */ +- initWithSeekableStream: (OFSeekableStream*)stream; + +/*! + * @brief Initializes an already allocated OFZIPArchive object with the * specified file. * * @param path The path to the ZIP file * @return An initialized OFZIPArchive */ @@ -81,11 +98,15 @@ */ - (OFString*)archiveComment; /*! * @brief Returns a stream for reading the specified file from the archive. + * + * @warning Calling @ref streamForReadingFile: will invalidate all streams + * previously returned by @ref streamForReadingFile:! Reading from an + * invalidated stream will throw an @ref OFReadFailedException! * * @param path The path to the file inside the archive * @return A stream for reading the specified file form the archive */ - (OFStream*)streamForReadingFile: (OFString*)path; @end