Overview
Comment: | OFSeekableStream: Add OFSeekWhence enum |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
73f5e3aa84bbc5ffd9828f8cfcdfcc8e |
User & Date: | js on 2022-08-27 20:58:46 |
Other Links: | manifest | tags |
Context
2022-08-27
| ||
21:24 | OFTarArchiveEntry: Rename size to uncompressedSize check-in: 98c64d0af9 user: js tags: trunk | |
20:58 | OFSeekableStream: Add OFSeekWhence enum check-in: 73f5e3aa84 user: js tags: trunk | |
20:46 | OFZIPArchive: Restore accidentally dropped cast check-in: 6ae6830243 user: js tags: trunk | |
Changes
Modified src/OFFile.m from [8cbc43a8f0] to [233f3b1153].
︙ | |||
447 448 449 450 451 452 453 | 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | - + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + | errNo: errno]; #endif return (size_t)bytesWritten; } - (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset |
︙ |
Modified src/OFLHAArchive.m from [16be8d0f67] to [356333f064].
︙ | |||
108 109 110 111 112 113 114 | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | - + | if ((_mode == modeWrite || _mode == modeAppend) && ![_stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; if (_mode == modeAppend) [(OFSeekableStream *)_stream seekToOffset: 0 |
︙ | |||
396 397 398 399 400 401 402 | 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | - + | stream = _stream; } if ([stream isKindOfClass: [OFSeekableStream class]] && (sizeof(OFStreamOffset) > 4 || toRead != (OFStreamOffset)toRead)) [(OFSeekableStream *)stream seekToOffset: (OFStreamOffset)toRead |
︙ | |||
442 443 444 445 446 447 448 | 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | - + | { self = [super init]; @try { _entry = [entry mutableCopy]; _encoding = encoding; |
︙ | |||
521 522 523 524 525 526 527 | 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | - - + + - + | if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; _entry.uncompressedSize = _bytesWritten; _entry.compressedSize = _bytesWritten; _entry.CRC16 = _CRC16; |
Modified src/OFMemoryStream.m from [0ce810b341] to [d9d07c7da0].
︙ | |||
98 99 100 101 102 103 104 | 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 | - + - + - + - + | - (bool)lowlevelIsAtEndOfStream { return (_position == _size); } - (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset |
︙ |
Modified src/OFSeekableStream.h from [7f5f12c98e] to [283dab88b6].
︙ | |||
25 26 27 28 29 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 | 25 26 27 28 29 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 | + + + + + + + + + + + + + + - + - - - - - - - + + - + - - - - - - - + | #ifdef OF_HAVE_SYS_TYPES_H # include <sys/types.h> #endif #import "OFStream.h" OF_ASSUME_NONNULL_BEGIN /** @file */ #if defined(OF_WINDOWS) typedef __int64 OFStreamOffset; #elif defined(OF_ANDROID) typedef long long OFStreamOffset; #elif defined(OF_MORPHOS) typedef signed long long OFStreamOffset; #elif defined(OF_HAVE_OFF64_T) typedef off64_t OFStreamOffset; #else typedef off_t OFStreamOffset; #endif /** * @brief From where to seek. */ typedef enum { /** Seek to the end of the stream + offset. */ OFSeekSet, /** Seek to the current location + offset. */ OFSeekCurrent, /** Seek to the specified byte. */ OFSeekEnd } OFSeekWhence; /** * @class OFSeekableStream OFSeekableStream.h ObjFW/OFSeekableStream.h * * @brief A stream that supports seeking. * * @note If you want to subclass this, override * @ref lowlevelSeekToOffset:whence:. OFSeekableStream uses this method * and makes it work together with the caching of OFStream. If you * override this methods without the `lowlevel` prefix, you *will* break * caching, get broken results and seek to the wrong position! */ @interface OFSeekableStream: OFStream { OF_RESERVE_IVARS(OFSeekableStream, 4) } /** * @brief Seeks to the specified offset. * * @param offset The offset in bytes |
Modified src/OFSeekableStream.m from [562c4a07bd] to [b6c980d4ae].
︙ | |||
35 36 37 38 39 40 41 | 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 | - + - + + - + | } } return [super init]; } - (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset |
Modified src/OFTarArchive.m from [acb7a099c2] to [4ba7eaf65d].
︙ | |||
96 97 98 99 100 101 102 | 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 | - + - + | uint32_t buffer[1024 / sizeof(uint32_t)]; bool empty = true; if (![_stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; [(OFSeekableStream *)_stream seekToOffset: -1024 |
︙ | |||
361 362 363 364 365 366 367 | 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | - + - + | if ([_stream isKindOfClass: [OFSeekableStream class]] && _toRead <= LLONG_MAX && (OFStreamOffset)_toRead == (long long)_toRead) { unsigned long long size; [(OFSeekableStream *)_stream seekToOffset: (OFStreamOffset)_toRead |
︙ |
Modified src/OFZIPArchive.m from [038073c897] to [c774e7280c].
︙ | |||
138 139 140 141 142 143 144 | 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | - + | *size -= 8; return field; } static void seekOrThrowInvalidFormat(OFSeekableStream *stream, |
︙ | |||
197 198 199 200 201 202 203 | 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | - + | [self of_readZIPInfo]; [self of_readEntries]; } if (_mode == modeAppend) { _offset = _centralDirectoryOffset; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, |
︙ | |||
260 261 262 263 264 265 266 | 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | - + | void *pool = objc_autoreleasePoolPush(); uint16_t commentLength; OFStreamOffset offset = -22; bool valid = false; do { seekOrThrowInvalidFormat((OFSeekableStream *)_stream, |
︙ | |||
293 294 295 296 297 298 299 | 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | - + - + | _centralDirectoryEntries == 0xFFFF || _centralDirectorySize == 0xFFFFFFFF || _centralDirectoryOffset == 0xFFFFFFFF) { int64_t offset64; uint64_t size; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, |
︙ | |||
351 352 353 354 355 356 357 | 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | - + | void *pool = objc_autoreleasePoolPush(); if (_centralDirectoryOffset < 0 || (OFStreamOffset)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, |
︙ | |||
447 448 449 450 451 452 453 | 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | - + | [self of_closeLastReturnedStream]; offset64 = entry.of_localFileHeaderOffset; if (offset64 < 0 || (OFStreamOffset)offset64 != offset64) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, |
︙ |
Modified src/exceptions/OFSeekFailedException.h from [f1d3a39ff6] to [cc5ff19519].
︙ | |||
24 25 26 27 28 29 30 | 24 25 26 27 28 29 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 | + - + - + - + - + | * * @brief An exception indicating that seeking in a stream failed. */ @interface OFSeekFailedException: OFException { OFSeekableStream *_stream; OFStreamOffset _offset; OFSeekWhence _whence; |
Modified src/exceptions/OFSeekFailedException.m from [1550412068] to [20812553c7].
︙ | |||
26 27 28 29 30 31 32 | 26 27 28 29 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 | - + - + | + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithStream: (OFSeekableStream *)stream offset: (OFStreamOffset)offset |
︙ |
Modified tests/OFMemoryStreamTests.m from [b4124576dd] to [14fae61fb2].
︙ | |||
45 46 47 48 49 50 51 | 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 | - + - + - + - + | memcmp(buffer, "fgh", 3) == 0 && [stream lowlevelReadIntoBuffer: buffer length: 10] == 5 && memcmp(buffer, "ijkl", 5) == 0) TEST(@"-[lowlevelIsAtEndOfStream]", [stream lowlevelIsAtEndOfStream]) TEST(@"-[lowlevelSeekToOffset:whence:]", |