Overview
Comment: | OFZIPArchive: Prepare for adding write support |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
22a6ad346c92f7c54c5da7cf82882c39 |
User & Date: | js on 2017-08-02 20:04:10 |
Other Links: | manifest | tags |
Context
2017-08-02
| ||
20:11 | OFTarArchive: Prepare for adding write support check-in: 9104575517 user: js tags: trunk | |
20:04 | OFZIPArchive: Prepare for adding write support check-in: 22a6ad346c user: js tags: trunk | |
2017-08-01
| ||
13:55 | OFApplication: Don't use SA_RESTART check-in: 4557cfb743 user: js tags: trunk | |
Changes
Modified src/OFZIPArchive.h from [b61ed08fb0] to [86ef82b330].
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | * @class OFZIPArchive OFZIPArchive.h ObjFW/OFZIPArchive.h * * @brief A class for accessing and manipulating ZIP files. */ @interface OFZIPArchive: OFObject { OFSeekableStream *_stream; uint32_t _diskNumber, _centralDirectoryDisk; uint64_t _centralDirectoryEntriesInDisk, _centralDirectoryEntries; uint64_t _centralDirectorySize; int64_t _centralDirectoryOffset; OFString *_archiveComment; OFMutableArray OF_GENERIC(OFZIPArchiveEntry *) *_entries; OFMutableDictionary OF_GENERIC(OFString *, OFZIPArchiveEntry *) *_pathToEntryMap; OFStream *_lastReturnedStream; } /*! * The archive comment. */ @property (readonly, nonatomic) OFString *archiveComment; /*! * @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 */ | > > > > > > > > | > > > > | > > > > | > > > > | > > > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | * @class OFZIPArchive OFZIPArchive.h ObjFW/OFZIPArchive.h * * @brief A class for accessing and manipulating ZIP files. */ @interface OFZIPArchive: OFObject { OFSeekableStream *_stream; enum { OF_ZIP_ARCHIVE_MODE_READ, OF_ZIP_ARCHIVE_MODE_WRITE, OF_ZIP_ARCHIVE_MODE_APPEND } _mode; uint32_t _diskNumber, _centralDirectoryDisk; uint64_t _centralDirectoryEntriesInDisk, _centralDirectoryEntries; uint64_t _centralDirectorySize; int64_t _centralDirectoryOffset; OFString *_archiveComment; OFMutableArray OF_GENERIC(OFZIPArchiveEntry *) *_entries; OFMutableDictionary OF_GENERIC(OFString *, OFZIPArchiveEntry *) *_pathToEntryMap; OFStream *_lastReturnedStream; } /*! * The archive comment. */ @property (readonly, nonatomic) OFString *archiveComment; /*! * @brief Creates a new OFZIPArchive object with the specified seekable stream. * * @param stream A seekable stream from which the ZIP archive will be read * @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 * file. * @return A new, autoreleased OFZIPArchive */ + (instancetype)archiveWithSeekableStream: (OFSeekableStream *)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 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 * file. * @return A new, autoreleased OFZIPArchive */ + (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode; #endif - init OF_UNAVAILABLE; /*! * @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 * @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 * file. * @return An initialized OFZIPArchive */ - initWithSeekableStream: (OFSeekableStream *)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 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 * file. * @return An initialized OFZIPArchive */ - initWithPath: (OFString *)path mode: (OFString *)mode; #endif /*! * @brief Returns the entries of the central directory of the archive as an * array of objects of class @ref OFZIPArchiveEntry. * * The objects of the array have the same order as the entries in the central * directory, which does not need to be the order in which the actual files are * stored. * * @return The entries of the central directory of the archive as an array */ - (OFArray OF_GENERIC(OFZIPArchiveEntry *) *)entries; /*! * @brief Returns a stream for reading the specified file from the archive. * * This method is only available in read and append mode. * * @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 OF_ASSUME_NONNULL_END |
Modified src/OFZIPArchive.m from [8c3891b987] to [c549fb1fd1].
︙ | ︙ | |||
133 134 135 136 137 138 139 140 | } } @implementation OFZIPArchive @synthesize archiveComment = _archiveComment; + (instancetype)archiveWithSeekableStream: (OFSeekableStream *)stream { | > | > > | > > > > > | | > > > | | > | 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | } } @implementation OFZIPArchive @synthesize archiveComment = _archiveComment; + (instancetype)archiveWithSeekableStream: (OFSeekableStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithSeekableStream: stream mode: mode] autorelease]; } #ifdef OF_HAVE_FILES + (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode { return [[[self alloc] initWithPath: path mode: mode] autorelease]; } #endif - init { OF_INVALID_INIT_METHOD } - initWithSeekableStream: (OFSeekableStream *)stream mode: (OFString *)mode { self = [super init]; @try { _stream = [stream retain]; if ([mode isEqual: @"r"]) { _mode = OF_ZIP_ARCHIVE_MODE_READ; [self of_readZIPInfo]; [self of_readEntries]; } else @throw [OFInvalidArgumentException exception]; } @catch (id e) { [self release]; @throw e; } return self; } #ifdef OF_HAVE_FILES - initWithPath: (OFString *)path mode: (OFString *)mode { OFFile *file = [[OFFile alloc] initWithPath: path mode: mode]; @try { self = [self initWithSeekableStream: file mode: mode]; } @finally { [file release]; } return self; } #endif |
︙ | ︙ | |||
325 326 327 328 329 330 331 | - (OFStream *)streamForReadingFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFZIPArchiveEntry *entry = [_pathToEntryMap objectForKey: path]; OFZIPArchive_LocalFileHeader *localFileHeader; int64_t offset64; | > > > | > | 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | - (OFStream *)streamForReadingFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFZIPArchiveEntry *entry = [_pathToEntryMap objectForKey: path]; OFZIPArchive_LocalFileHeader *localFileHeader; int64_t offset64; if (_mode != OF_ZIP_ARCHIVE_MODE_READ && _mode != OF_ZIP_ARCHIVE_MODE_APPEND) @throw [OFInvalidArgumentException exception]; if ((entry = [_pathToEntryMap objectForKey: path]) == nil) @throw [OFOpenItemFailedException exceptionWithPath: path mode: @"r" errNo: ENOENT]; [_lastReturnedStream close]; [_lastReturnedStream release]; _lastReturnedStream = nil; |
︙ | ︙ |
Modified utils/ofzip/ZIPArchive.m from [15729aa028] to [01768df2ad].
︙ | ︙ | |||
63 64 65 66 67 68 69 | - initWithStream: (OF_KINDOF(OFStream *))stream { self = [super init]; @try { _archive = [[OFZIPArchive alloc] | | > | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | - initWithStream: (OF_KINDOF(OFStream *))stream { self = [super init]; @try { _archive = [[OFZIPArchive alloc] initWithSeekableStream: stream mode: @"r"]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ |