Differences From Artifact [7e042e0447]:
- File
src/OFStream.m
— part of check-in
[f9cd4f9cab]
at
2017-06-05 15:51:48
on branch trunk
— OFStream: Don't throw when at end of stream
Instead, let reads return 0 and let writes append after the end. (user: js, size: 33838) [annotate] [blame] [check-ins using]
To Artifact [d30563e398]:
- File src/OFStream.m — part of check-in [c8f7b90082] at 2017-07-22 20:50:27 on branch trunk — Split OFDataArray into OFData and OFMutableData (user: js, size: 33954) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
34 35 36 37 38 39 40 | #if !defined(OF_WINDOWS) && !defined(OF_MORPHOS) # include <signal.h> #endif #import "OFStream.h" #import "OFStream+Private.h" #import "OFString.h" | | > | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #if !defined(OF_WINDOWS) && !defined(OF_MORPHOS) # include <signal.h> #endif #import "OFStream.h" #import "OFStream+Private.h" #import "OFString.h" #import "OFData.h" #import "OFSystemInfo.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFSetOptionFailedException.h" #import "OFTruncatedDataException.h" #import "of_asprintf.h" #define MIN_READ_SIZE 512 |
︙ | ︙ | |||
550 551 552 553 554 555 556 | for (size_t i = 0; i < count; i++) buffer[i] = OF_BSWAP_DOUBLE(buffer[i]); #endif return size; } | | | | | | | | > > | > | | | | > | > | | > | | < < < | < | | | | > > | | 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | for (size_t i = 0; i < count; i++) buffer[i] = OF_BSWAP_DOUBLE(buffer[i]); #endif return size; } - (OFData *)readDataWithCount: (size_t)count { return [self readDataWithItemSize: 1 count: count]; } - (OFData *)readDataWithItemSize: (size_t)itemSize count: (size_t)count { OFData *ret; char *buffer; if OF_UNLIKELY (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; if OF_UNLIKELY ((buffer = malloc(count * itemSize)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: count * itemSize]; @try { [self readIntoBuffer: buffer exactLength: count * itemSize]; ret = [OFData dataWithItemsNoCopy: buffer itemSize: itemSize count: count freeWhenDone: true]; } @catch (id e) { free(buffer); @throw e; } return ret; } - (OFData *)readDataUntilEndOfStream { OFMutableData *data = [OFMutableData data]; size_t pageSize = [OFSystemInfo pageSize]; char *buffer = [self allocMemoryWithSize: pageSize]; @try { while (![self isAtEndOfStream]) { size_t length; length = [self readIntoBuffer: buffer length: pageSize]; [data addItems: buffer count: length]; } } @finally { [self freeMemory: buffer]; } [data makeImmutable]; return data; } - (OFString *)readStringWithLength: (size_t)length { return [self readStringWithLength: length encoding: OF_STRING_ENCODING_UTF_8]; } |
︙ | ︙ | |||
1439 1440 1441 1442 1443 1444 1445 | [self freeMemory: tmp]; } #endif return size; } | | | | | 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 | [self freeMemory: tmp]; } #endif return size; } - (size_t)writeData: (OFData *)data { size_t length = [data count] * [data itemSize]; [self writeBuffer: [data items] length: length]; return length; } - (size_t)writeString: (OFString *)string { |
︙ | ︙ |