︙ | | | ︙ | |
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
|
#import "OFWriteFailedException.h"
OF_DIRECT_MEMBERS
@interface OFTarArchiveFileReadStream: OFStream <OFReadyForReadingObserving>
{
OFTarArchiveEntry *_entry;
OFStream *_stream;
uint64_t _toRead;
bool _atEndOfStream, _skipped;
}
- (instancetype)of_initWithStream: (OFStream *)stream
entry: (OFTarArchiveEntry *)entry;
- (void)of_skip;
@end
OF_DIRECT_MEMBERS
@interface OFTarArchiveFileWriteStream: OFStream <OFReadyForWritingObserving>
{
OFTarArchiveEntry *_entry;
OFStream *_stream;
uint64_t _toWrite;
}
- (instancetype)of_initWithStream: (OFStream *)stream
entry: (OFTarArchiveEntry *)entry;
@end
@implementation OFTarArchive: OFObject
|
|
|
|
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
|
#import "OFWriteFailedException.h"
OF_DIRECT_MEMBERS
@interface OFTarArchiveFileReadStream: OFStream <OFReadyForReadingObserving>
{
OFTarArchiveEntry *_entry;
OFStream *_stream;
unsigned long long _toRead;
bool _atEndOfStream, _skipped;
}
- (instancetype)of_initWithStream: (OFStream *)stream
entry: (OFTarArchiveEntry *)entry;
- (void)of_skip;
@end
OF_DIRECT_MEMBERS
@interface OFTarArchiveFileWriteStream: OFStream <OFReadyForWritingObserving>
{
OFTarArchiveEntry *_entry;
OFStream *_stream;
unsigned long long _toWrite;
}
- (instancetype)of_initWithStream: (OFStream *)stream
entry: (OFTarArchiveEntry *)entry;
@end
@implementation OFTarArchive: OFObject
|
︙ | | | ︙ | |
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
if (_stream == nil)
@throw [OFNotOpenException exceptionWithObject: self];
if (_atEndOfStream)
return 0;
#if SIZE_MAX >= UINT64_MAX
if (length > UINT64_MAX)
@throw [OFOutOfRangeException exception];
#endif
if ((uint64_t)length > _toRead)
length = (size_t)_toRead;
ret = [_stream readIntoBuffer: buffer length: length];
if (ret == 0)
_atEndOfStream = true;
_toRead -= ret;
|
|
|
|
|
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
if (_stream == nil)
@throw [OFNotOpenException exceptionWithObject: self];
if (_atEndOfStream)
return 0;
#if SIZE_MAX >= ULLONG_MAX
if (length > ULLONG_MAX)
@throw [OFOutOfRangeException exception];
#endif
if ((unsigned long long)length > _toRead)
length = (size_t)_toRead;
ret = [_stream readIntoBuffer: buffer length: length];
if (ret == 0)
_atEndOfStream = true;
_toRead -= ret;
|
︙ | | | ︙ | |
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
- (void)of_skip
{
if (_stream == nil || _skipped)
return;
if ([_stream isKindOfClass: [OFSeekableStream class]] &&
_toRead <= INT64_MAX &&
(OFStreamOffset)_toRead == (int64_t)_toRead) {
uint64_t size;
[(OFSeekableStream *)_stream
seekToOffset: (OFStreamOffset)_toRead
whence: SEEK_CUR];
_toRead = 0;
size = _entry.size;
if (size % 512 != 0)
[(OFSeekableStream *)_stream
seekToOffset: 512 - (size % 512)
whence: SEEK_CUR];
} else {
char buffer[512];
uint64_t size;
while (_toRead >= 512) {
[_stream readIntoBuffer: buffer exactLength: 512];
_toRead -= 512;
}
if (_toRead > 0) {
|
|
|
|
|
|
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
- (void)of_skip
{
if (_stream == nil || _skipped)
return;
if ([_stream isKindOfClass: [OFSeekableStream class]] &&
_toRead <= LLONG_MAX &&
(OFStreamOffset)_toRead == (long long)_toRead) {
unsigned long long size;
[(OFSeekableStream *)_stream
seekToOffset: (OFStreamOffset)_toRead
whence: SEEK_CUR];
_toRead = 0;
size = _entry.size;
if (size % 512 != 0)
[(OFSeekableStream *)_stream
seekToOffset: 512 - (size % 512)
whence: SEEK_CUR];
} else {
char buffer[512];
unsigned long long size;
while (_toRead >= 512) {
[_stream readIntoBuffer: buffer exactLength: 512];
_toRead -= 512;
}
if (_toRead > 0) {
|
︙ | | | ︙ | |
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
}
- (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length
{
if (_stream == nil)
@throw [OFNotOpenException exceptionWithObject: self];
if ((uint64_t)length > _toWrite)
@throw [OFOutOfRangeException exception];
@try {
[_stream writeBuffer: buffer length: length];
} @catch (OFWriteFailedException *e) {
OFEnsure(e.bytesWritten <= length);
|
|
|
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
}
- (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length
{
if (_stream == nil)
@throw [OFNotOpenException exceptionWithObject: self];
if (length > _toWrite)
@throw [OFOutOfRangeException exception];
@try {
[_stream writeBuffer: buffer length: length];
} @catch (OFWriteFailedException *e) {
OFEnsure(e.bytesWritten <= length);
|
︙ | | | ︙ | |
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
{
return ((id <OFReadyForWritingObserving>)_stream)
.fileDescriptorForWriting;
}
- (void)close
{
uint64_t remainder;
if (_stream == nil)
@throw [OFNotOpenException exceptionWithObject: self];
if (_toWrite > 0)
@throw [OFTruncatedDataException exception];
|
|
|
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
{
return ((id <OFReadyForWritingObserving>)_stream)
.fileDescriptorForWriting;
}
- (void)close
{
unsigned long long remainder;
if (_stream == nil)
@throw [OFNotOpenException exceptionWithObject: self];
if (_toWrite > 0)
@throw [OFTruncatedDataException exception];
|
︙ | | | ︙ | |