Differences From Artifact [969975ba2f]:
- File src/OFTarArchive.m — part of check-in [9db1965939] at 2018-05-26 07:56:22 on branch trunk — OFTarArchive: Allow specifying the encoding (user: js, size: 9736) [annotate] [blame] [check-ins using]
To Artifact [d5ac892200]:
- File
src/OFTarArchive.m
— part of check-in
[790b5344d6]
at
2018-05-26 23:04:24
on branch trunk
— Add OFLHAArchive
This is currently limited to reading uncompressed LHA level 2 files. (user: js, size: 9874) [annotate] [blame] [check-ins using]
| ︙ | ︙ | |||
38 39 40 41 42 43 44 |
{
OFTarArchiveEntry *_entry;
OF_KINDOF(OFStream *) _stream;
uint64_t _toRead;
bool _atEndOfStream;
}
| | | | | > > > > > | 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 |
{
OFTarArchiveEntry *_entry;
OF_KINDOF(OFStream *) _stream;
uint64_t _toRead;
bool _atEndOfStream;
}
- (instancetype)of_initWithStream: (OFStream *)stream
entry: (OFTarArchiveEntry *)entry;
- (void)of_skip;
@end
@interface OFTarArchive_FileWriteStream: OFStream <OFReadyForWritingObserving>
{
OFTarArchiveEntry *_entry;
OF_KINDOF(OFStream *) _stream;
uint64_t _toWrite;
}
- (instancetype)of_initWithStream: (OFStream *)stream
entry: (OFTarArchiveEntry *)entry;
@end
@implementation OFTarArchive: OFObject
@synthesize encoding = _encoding;
+ (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream
mode: (OFString *)mode
{
return [[[self alloc] initWithStream: stream
mode: mode] autorelease];
}
#ifdef OF_HAVE_FILES
+ (instancetype)archiveWithPath: (OFString *)path
mode: (OFString *)mode
{
return [[[self alloc] initWithPath: path
mode: mode] autorelease];
}
#endif
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithStream: (OF_KINDOF(OFStream *))stream
mode: (OFString *)mode
{
self = [super init];
@try {
|
| ︙ | ︙ | |||
199 200 201 202 203 204 205 | } entry = [[[OFTarArchiveEntry alloc] of_initWithHeader: buffer.c encoding: _encoding] autorelease]; _lastReturnedStream = [[OFTarArchive_FileReadStream alloc] | | | | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
}
entry = [[[OFTarArchiveEntry alloc]
of_initWithHeader: buffer.c
encoding: _encoding] autorelease];
_lastReturnedStream = [[OFTarArchive_FileReadStream alloc]
of_initWithStream: _stream
entry: entry];
return entry;
}
- (OFStream <OFReadyForReadingObserving> *)streamForReadingCurrentEntry
{
if (_mode != OF_TAR_ARCHIVE_MODE_READ)
|
| ︙ | ︙ | |||
235 236 237 238 239 240 241 | [_lastReturnedStream release]; _lastReturnedStream = nil; [entry of_writeToStream: _stream encoding: _encoding]; _lastReturnedStream = [[OFTarArchive_FileWriteStream alloc] | | | | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | [_lastReturnedStream release]; _lastReturnedStream = nil; [entry of_writeToStream: _stream encoding: _encoding]; _lastReturnedStream = [[OFTarArchive_FileWriteStream alloc] of_initWithStream: _stream entry: entry]; objc_autoreleasePoolPop(pool); return [[_lastReturnedStream retain] autorelease]; } - (void)close |
| ︙ | ︙ | |||
266 267 268 269 270 271 272 | [_stream release]; _stream = nil; } @end @implementation OFTarArchive_FileReadStream | | | | 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
[_stream release];
_stream = nil;
}
@end
@implementation OFTarArchive_FileReadStream
- (instancetype)of_initWithStream: (OFStream *)stream
entry: (OFTarArchiveEntry *)entry
{
self = [super init];
@try {
_entry = [entry copy];
_stream = [stream retain];
_toRead = [entry size];
|
| ︙ | ︙ | |||
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
- (int)fileDescriptorForReading
{
return [_stream fileDescriptorForReading];
}
- (void)close
{
[_stream release];
_stream = nil;
[super close];
}
- (void)of_skip
{
if ([_stream isKindOfClass: [OFSeekableStream class]] &&
_toRead <= INT64_MAX && (of_offset_t)_toRead == (int64_t)_toRead) {
uint64_t size;
[_stream seekToOffset: (of_offset_t)_toRead
whence: SEEK_CUR];
| > > > > > | 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
- (int)fileDescriptorForReading
{
return [_stream fileDescriptorForReading];
}
- (void)close
{
[self of_skip];
[_stream release];
_stream = nil;
[super close];
}
- (void)of_skip
{
if (_stream == nil || _toRead == 0)
return;
if ([_stream isKindOfClass: [OFSeekableStream class]] &&
_toRead <= INT64_MAX && (of_offset_t)_toRead == (int64_t)_toRead) {
uint64_t size;
[_stream seekToOffset: (of_offset_t)_toRead
whence: SEEK_CUR];
|
| ︙ | ︙ | |||
390 391 392 393 394 395 396 | [_stream readIntoBuffer: buffer exactLength: (size_t)(512 - (size % 512))]; } } @end @implementation OFTarArchive_FileWriteStream | | | | 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
[_stream readIntoBuffer: buffer
exactLength: (size_t)(512 - (size % 512))];
}
}
@end
@implementation OFTarArchive_FileWriteStream
- (instancetype)of_initWithStream: (OFStream *)stream
entry: (OFTarArchiveEntry *)entry
{
self = [super init];
@try {
_entry = [entry copy];
_stream = [stream retain];
_toWrite = [entry size];
|
| ︙ | ︙ |