Differences From Artifact [dc06a91f23]:
- File
src/OFLHAArchive.m
— part of check-in
[1a6e3816c1]
at
2018-05-27 07:32:22
on branch trunk
— OFLHAArchiveEntry: Keep the method as a string
It is only necessary to extract files, so it makes sense to keep it as
is to be able to list files using an unknown method. (user: js, size: 5515) [annotate] [blame] [check-ins using]
To Artifact [1011e54787]:
- File src/OFLHAArchive.m — part of check-in [57f9bc6ace] at 2018-05-27 11:07:03 on branch trunk — OFLHAArchiveEntry: Add support for LHA level 0 (user: js, size: 5964) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
26 27 28 29 30 31 32 33 34 35 | #import "OFStream.h" #import "OFSeekableStream.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" @interface OFLHAArchive_FileReadStream: OFStream <OFReadyForReadingObserving> { | > < | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #import "OFStream.h" #import "OFSeekableStream.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFTruncatedDataException.h" @interface OFLHAArchive_FileReadStream: OFStream <OFReadyForReadingObserving> { OF_KINDOF(OFStream *) _stream; uint32_t _toRead; bool _atEndOfStream; } - (instancetype)of_initWithStream: (OFStream *)stream entry: (OFLHAArchiveEntry *)entry; |
︙ | ︙ | |||
118 119 120 121 122 123 124 | [self close]; [super dealloc]; } - (OFLHAArchiveEntry *)nextEntry { | | | > > > > | > | < | | > > | < > > | > | | | | | | > > > > > > > > > > > > > < < < < < < < < > > > > > | < < | 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | [self close]; [super dealloc]; } - (OFLHAArchiveEntry *)nextEntry { char header[21]; size_t headerLen; [_lastEntry release]; _lastEntry = nil; [_lastReturnedStream of_skip]; [_lastReturnedStream close]; [_lastReturnedStream release]; _lastReturnedStream = nil; for (headerLen = 0; headerLen < 21;) { if ([_stream isAtEndOfStream]) { if (headerLen == 0) return nil; if (headerLen == 1 && header[0] == 0) return nil; @throw [OFTruncatedDataException exception]; } headerLen += [_stream readIntoBuffer: header + headerLen length: 21 - headerLen]; } _lastEntry = [[OFLHAArchiveEntry alloc] of_initWithHeader: header stream: _stream encoding: _encoding]; _lastReturnedStream = [[OFLHAArchive_FileReadStream alloc] of_initWithStream: _stream entry: _lastEntry]; return [[_lastEntry copy] autorelease]; } - (OFStream <OFReadyForReadingObserving> *)streamForReadingCurrentEntry { OFString *method; if (_lastReturnedStream == nil) @throw [OFInvalidArgumentException exception]; method = [_lastEntry method]; if (![method isEqual: @"-lh0-"] && ![method isEqual: @"-lhd-"] && ![method isEqual: @"-lz4-"]) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; return [[_lastReturnedStream retain] autorelease]; } - (void)close { if (_stream == nil) return; [_lastEntry release]; _lastEntry = nil; [_lastReturnedStream close]; [_lastReturnedStream release]; _lastReturnedStream = nil; [_stream release]; _stream = nil; } @end @implementation OFLHAArchive_FileReadStream - (instancetype)of_initWithStream: (OFStream *)stream entry: (OFLHAArchiveEntry *)entry { self = [super init]; @try { _stream = [stream retain]; /* * Use the compressed size, as that is the number of bytes we * need to skip for the next entry and is equal for * uncompressed files, the only thing supported so far. */ _toRead = [entry compressedSize]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [self close]; [super dealloc]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { size_t ret; |
︙ | ︙ |