@@ -19,11 +19,10 @@ OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFStream; -@class OFTarArchive_FileReadStream; /*! * @class OFTarArchive OFTarArchive.h ObjFW/OFTarArchive.h * * @brief A class for accessing and manipulating tar archives. @@ -34,20 +33,21 @@ enum { OF_TAR_ARCHIVE_MODE_READ, OF_TAR_ARCHIVE_MODE_WRITE, OF_TAR_ARCHIVE_MODE_APPEND } _mode; - OFTarArchive_FileReadStream *_lastReturnedStream; + OF_KINDOF(OFStream *) _lastReturnedStream; } /*! * @brief Creates a new OFTarArchive object with the specified stream. * - * @param stream A stream from which the tar archive will be read + * @param stream A stream from which the tar archive will be read. + * For append mode, this needs to be a seekable stream. * @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 - * file. + * archive. * @return A new, autoreleased OFTarArchive */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; @@ -56,11 +56,11 @@ * @brief Creates a new OFTarArchive object with the specified file. * * @param path The path to the tar archive * @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 - * file. + * archive. * @return A new, autoreleased OFTarArchive */ + (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode; #endif @@ -67,14 +67,15 @@ /*! * @brief Initializes an already allocated OFTarArchive object with the * specified stream. * - * @param stream A stream from which the tar archive will be read + * @param stream A stream from which the tar archive will be read. + * For append mode, this needs to be a seekable stream. * @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 - * file. + * archive. * @return An initialized OFTarArchive */ - initWithStream: (OFStream *)stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; @@ -84,11 +85,11 @@ * specified file. * * @param path The path to the tar archive * @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 - * file. + * archive. * @return An initialized OFTarArchive */ - initWithPath: (OFString *)path mode: (OFString *)mode; #endif @@ -98,12 +99,14 @@ * have been read. * * This is only available in read mode. * * @warning Calling @ref nextEntry will invalidate all streams returned by - * @ref streamForReadingCurrentEntry entry! Reading from an - * invalidated stream will throw an @ref OFReadFailedException! + * @ref streamForReadingCurrentEntry or + * @ref streamForWritingEntry:! Reading from or writing to an + * invalidated stream will throw an @ref OFReadFailedException or + * @ref OFWriteFailedException! * * @return The next entry from the tar archive or `nil` if all entries have * been read */ - (OFTarArchiveEntry *)nextEntry; @@ -112,8 +115,27 @@ * @brief Returns a stream for reading the current entry. * * @return A stream for reading the current entry */ - (OFStream *)streamForReadingCurrentEntry; + +/*! + * @brief Returns a stream for writing the specified entry. + * + * @warning Calling @ref nextEntry will invalidate all streams returned by + * @ref streamForReadingCurrentEntry or + * @ref streamForWritingEntry:! Reading from or writing to an + * invalidated stream will throw an @ref OFReadFailedException or + * @ref OFWriteFailedException! + * + * @param entry The entry for which a stream for writing should be returned + * @return A stream for writing the specified entry + */ +- (OFStream *)streamForWritingEntry: (OFTarArchiveEntry *)entry; + +/*! + * @brief Closes the OFTarArchive. + */ +- (void)close; @end OF_ASSUME_NONNULL_END