ObjFW  Diff

Differences From Artifact [2ae2007028]:

To Artifact [7c9dae9bb4]:


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
102
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
+ (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode
			     mode: (OFString *)mode
{
	return [[[self alloc] initWithStream: stream
	return [[[self alloc] initWithStream: stream mode: mode] autorelease];
					mode: mode] autorelease];
}

#ifdef OF_HAVE_FILES
+ (instancetype)archiveWithPath: (OFString *)path
+ (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode
			   mode: (OFString *)mode
{
	return [[[self alloc] initWithPath: path
	return [[[self alloc] initWithPath: path mode: mode] autorelease];
				      mode: mode] autorelease];
}
#endif

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithStream: (OFStream *)stream
- (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode
			  mode: (OFString *)mode
{
	self = [super init];

	@try {
		_stream = [stream retain];

		if ([mode isEqual: @"r"])
123
124
125
126
127
128
129
130

131
132
133
134
135
136

137
138
139

140
141
142
143

144
145
146
147
148
149
150
151
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
- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode
			mode: (OFString *)mode
{
	OFFile *file;

	if ([mode isEqual: @"a"])
		file = [[OFFile alloc] initWithPath: path
		file = [[OFFile alloc] initWithPath: path mode: @"r+"];
					       mode: @"r+"];
	else
		file = [[OFFile alloc] initWithPath: path
		file = [[OFFile alloc] initWithPath: path mode: mode];
					       mode: mode];

	@try {
		self = [self initWithStream: file
		self = [self initWithStream: file mode: mode];
				       mode: mode];
	} @finally {
		[file release];
	}

	return self;
}
#endif
321
322
323
324
325
326
327
328

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345

346
347
348
349
350
351
352
353
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
- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length
			  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
	ret = [_decompressedStream readIntoBuffer: buffer length: length];
					   length: length];

	_toRead -= ret;
	_CRC16 = of_crc16(_CRC16, buffer, ret);

	if (_toRead == 0) {
		_atEndOfStream = true;

413
414
415
416
417
418
419
420

421
422
423
424
425
426
427
428
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
			toRead -= [stream readIntoBuffer: buffer length: min];
						  length: min];
		}
	}

	_toRead = 0;
	_skipped = true;
}

450
451
452
453
454
455
456
457

458
459

460
461
462
463
464
465
466
467
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
		_headerOffset = [stream seekToOffset: 0 whence: SEEK_CUR];
					       whence: SEEK_CUR];
		[_entry of_writeToStream: stream
		[_entry of_writeToStream: stream encoding: _encoding];
				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) {
478
479
480
481
482
483
484
485

486
487
488
489
490
491
492
493
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
- (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length
		       length: (size_t)length
{
	uint32_t bytesWritten;

	if (_stream == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (UINT32_MAX - _bytesWritten < length)
530
531
532
533
534
535
536
537

538
539

540
541

542
543

544
545
546
547
548
549
550
551
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
	offset = [_stream seekToOffset: 0 whence: SEEK_CUR];
				whence:SEEK_CUR];
	[_stream seekToOffset: _headerOffset
	[_stream seekToOffset: _headerOffset whence: SEEK_SET];
		       whence: SEEK_SET];
	[_entry of_writeToStream: _stream
	[_entry of_writeToStream: _stream encoding: _encoding];
			encoding: _encoding];
	[_stream seekToOffset: offset
	[_stream seekToOffset: offset whence: SEEK_SET];
		       whence: SEEK_SET];

	[_stream release];
	_stream = nil;

	[super close];
}
@end