Differences From Artifact [d4b33ee3bc]:
- File
src/OFLHAArchive.m
— part of check-in
[9e9ce6aa1c]
at
2020-09-27 03:08:51
on branch trunk
— Work around bugs in Apple GCC 4.0.1
Still miscompiles things. (user: js, size: 12333) [annotate] [blame] [check-ins using] [more...]
To Artifact [7c9dae9bb4]:
- File src/OFLHAArchive.m — part of check-in [1b82d3bf4f] at 2021-03-07 20:25:21 on branch trunk — *.m: Fold methods into one line where it fits (user: js, size: 12102) [annotate] [blame] [check-ins using] [more...]
1 | /* | < < | | 1 2 3 4 5 6 7 8 9 | /* * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * |
︙ | ︙ | |||
68 69 70 71 72 73 74 | entry: (OFLHAArchiveEntry *)entry encoding: (of_string_encoding_t)encoding; @end @implementation OFLHAArchive @synthesize encoding = _encoding; | | < | < | < | < | < | 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 | entry: (OFLHAArchiveEntry *)entry encoding: (of_string_encoding_t)encoding; @end @implementation OFLHAArchive @synthesize encoding = _encoding; + (instancetype)archiveWithStream: (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: (OFStream *)stream mode: (OFString *)mode { self = [super init]; @try { _stream = [stream retain]; if ([mode isEqual: @"r"]) |
︙ | ︙ | |||
125 126 127 128 129 130 131 | @throw e; } return self; } #ifdef OF_HAVE_FILES | | < | < | < | < | 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 | @throw e; } return self; } #ifdef OF_HAVE_FILES - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode { OFFile *file; if ([mode isEqual: @"a"]) file = [[OFFile alloc] initWithPath: path mode: @"r+"]; else file = [[OFFile alloc] initWithPath: path mode: mode]; @try { self = [self initWithStream: file mode: mode]; } @finally { [file release]; } return self; } #endif |
︙ | ︙ | |||
323 324 325 326 327 328 329 | { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } | | < | < | 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { size_t ret; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; if (_stream.atEndOfStream && !_decompressedStream.hasDataInReadBuffer) @throw [OFTruncatedDataException exception]; if (length > _toRead) length = _toRead; ret = [_decompressedStream readIntoBuffer: buffer length: length]; _toRead -= ret; _CRC16 = of_crc16(_CRC16, buffer, ret); if (_toRead == 0) { _atEndOfStream = true; |
︙ | ︙ | |||
415 416 417 418 419 420 421 | while (toRead > 0) { char buffer[512]; size_t min = toRead; if (min > 512) min = 512; | | < | 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | while (toRead > 0) { char buffer[512]; size_t min = toRead; if (min > 512) min = 512; toRead -= [stream readIntoBuffer: buffer length: min]; } } _toRead = 0; _skipped = true; } |
︙ | ︙ | |||
452 453 454 455 456 457 458 | { self = [super init]; @try { _entry = [entry mutableCopy]; _encoding = encoding; | | < | < | 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | { self = [super init]; @try { _entry = [entry mutableCopy]; _encoding = encoding; _headerOffset = [stream seekToOffset: 0 whence: SEEK_CUR]; [_entry of_writeToStream: stream encoding: _encoding]; /* * Retain stream last, so that -[close] called by -[dealloc] * doesn't write in case of an error. */ _stream = [stream retain]; } @catch (id e) { |
︙ | ︙ | |||
480 481 482 483 484 485 486 | [self close]; [_entry release]; [super dealloc]; } | | < | 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | [self close]; [_entry release]; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { uint32_t bytesWritten; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (UINT32_MAX - _bytesWritten < length) |
︙ | ︙ | |||
532 533 534 535 536 537 538 | if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; _entry.uncompressedSize = _bytesWritten; _entry.compressedSize = _bytesWritten; _entry.CRC16 = _CRC16; | | < | < | < | < | 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; _entry.uncompressedSize = _bytesWritten; _entry.compressedSize = _bytesWritten; _entry.CRC16 = _CRC16; offset = [_stream seekToOffset: 0 whence: SEEK_CUR]; [_stream seekToOffset: _headerOffset whence: SEEK_SET]; [_entry of_writeToStream: _stream encoding: _encoding]; [_stream seekToOffset: offset whence: SEEK_SET]; [_stream release]; _stream = nil; [super close]; } @end |