Differences From Artifact [b0fcc38dae]:
- File src/OFData.m — part of check-in [93f0d2a78f] at 2022-10-20 16:37:26 on branch trunk — -[initWithContentsOfFile:]: Avoid stat call (user: js, size: 14190) [annotate] [blame] [check-ins using] [more...]
To Artifact [fedaecf95c]:
- File
src/OFData.m
— part of check-in
[6ce0093f8d]
at
2023-04-10 19:22:32
on branch trunk
— Remove OFSerialization
While the idea sounds nice that the tag name is the class, this means the
serialization includes whether something is mutable or immutable. This means
doing as much as making something immutable changes the serialization, which
can then cause issues after being deserialized. (user: js, size: 13201) [annotate] [blame] [check-ins using] [more...]
1 | /* | | | 1 2 3 4 5 6 7 8 9 | /* * Copyright (c) 2008-2023 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. * |
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 | #import "OFData.h" #import "OFBase64.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFStream.h" #import "OFString.h" #import "OFSystemInfo.h" | > > < < < | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #import "OFData.h" #import "OFBase64.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFStream.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" |
︙ | ︙ | |||
89 90 91 92 93 94 95 | #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path { return [[[self alloc] initWithContentsOfFile: path] autorelease]; } #endif | | | | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path { return [[[self alloc] initWithContentsOfFile: path] autorelease]; } #endif + (instancetype)dataWithContentsOfIRI: (OFIRI *)IRI { return [[[self alloc] initWithContentsOfIRI: IRI] autorelease]; } + (instancetype)dataWithStringRepresentation: (OFString *)string { return [[[self alloc] initWithStringRepresentation: string] autorelease]; } |
︙ | ︙ | |||
207 208 209 210 211 212 213 | @throw e; } return self; } #endif | | | | 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | @throw e; } return self; } #endif - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFStream *stream = [OFIRIHandler openItemAtIRI: IRI mode: @"r"]; size_t pageSize; unsigned char *buffer; _count = 0; _itemSize = 1; _freeWhenDone = true; |
︙ | ︙ | |||
330 331 332 333 334 335 336 | [self release]; @throw e; } if (!mutable) [(OFMutableData *)self makeImmutable]; | < < < < < < < < < < < < < < < < < < < < < < < | 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | [self release]; @throw e; } if (!mutable) [(OFMutableData *)self makeImmutable]; return self; } - (void)dealloc { if (_freeWhenDone) OFFreeMemory(_items); |
︙ | ︙ | |||
583 584 585 586 587 588 589 | [file writeBuffer: _items length: _count * _itemSize]; } @finally { [file release]; } } #endif | | | < < < < < < < < < < < < < < < < < < < < < < | 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | [file writeBuffer: _items length: _count * _itemSize]; } @finally { [file release]; } } #endif - (void)writeToIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); [[OFIRIHandler openItemAtIRI: IRI mode: @"w"] writeData: self]; objc_autoreleasePoolPop(pool); } - (OFData *)messagePackRepresentation { OFMutableData *data; if (_itemSize != 1) |
︙ | ︙ |