︙ | | | ︙ | |
19
20
21
22
23
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
|
#import "OFLHAArchive.h"
#import "OFLHAArchiveEntry.h"
#import "OFLHAArchiveEntry+Private.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#endif
#import "OFLHAArchive_LHStream.h"
#import "OFStream.h"
#import "OFSeekableStream.h"
#import "OFString.h"
#import "crc16.h"
#import "OFChecksumMismatchException.h"
#import "OFInvalidArgumentException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFWriteFailedException.h"
@interface OFLHAArchive_FileReadStream: OFStream <OFReadyForReadingObserving>
{
OFStream *_stream, *_decompressedStream;
OFLHAArchiveEntry *_entry;
uint32_t _toRead, _bytesConsumed;
uint16_t _CRC16;
bool _atEndOfStream, _skipped;
}
- (instancetype)of_initWithStream: (OFStream *)stream
entry: (OFLHAArchiveEntry *)entry;
- (void)of_skip;
@end
@interface OFLHAArchive_FileWriteStream: OFStream <OFReadyForWritingObserving>
{
OFMutableLHAArchiveEntry *_entry;
of_string_encoding_t _encoding;
OFSeekableStream *_stream;
of_offset_t _headerOffset;
uint32_t _bytesWritten;
uint16_t _CRC16;
|
|
|
|
|
19
20
21
22
23
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
|
#import "OFLHAArchive.h"
#import "OFLHAArchiveEntry.h"
#import "OFLHAArchiveEntry+Private.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#endif
#import "OFLHADecompressingStream.h"
#import "OFStream.h"
#import "OFSeekableStream.h"
#import "OFString.h"
#import "crc16.h"
#import "OFChecksumMismatchException.h"
#import "OFInvalidArgumentException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFWriteFailedException.h"
@interface OFLHAArchiveFileReadStream: OFStream <OFReadyForReadingObserving>
{
OFStream *_stream, *_decompressedStream;
OFLHAArchiveEntry *_entry;
uint32_t _toRead, _bytesConsumed;
uint16_t _CRC16;
bool _atEndOfStream, _skipped;
}
- (instancetype)of_initWithStream: (OFStream *)stream
entry: (OFLHAArchiveEntry *)entry;
- (void)of_skip;
@end
@interface OFLHAArchiveFileWriteStream: OFStream <OFReadyForWritingObserving>
{
OFMutableLHAArchiveEntry *_entry;
of_string_encoding_t _encoding;
OFSeekableStream *_stream;
of_offset_t _headerOffset;
uint32_t _bytesWritten;
uint16_t _CRC16;
|
︙ | | | ︙ | |
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
OFLHAArchiveEntry *entry;
char header[21];
size_t headerLen;
if (_mode != OF_LHA_ARCHIVE_MODE_READ)
@throw [OFInvalidArgumentException exception];
[(OFLHAArchive_FileReadStream *)_lastReturnedStream of_skip];
[_lastReturnedStream close];
[_lastReturnedStream release];
_lastReturnedStream = nil;
for (headerLen = 0; headerLen < 21;) {
if (_stream.atEndOfStream) {
if (headerLen == 0)
|
|
|
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
OFLHAArchiveEntry *entry;
char header[21];
size_t headerLen;
if (_mode != OF_LHA_ARCHIVE_MODE_READ)
@throw [OFInvalidArgumentException exception];
[(OFLHAArchiveFileReadStream *)_lastReturnedStream of_skip];
[_lastReturnedStream close];
[_lastReturnedStream release];
_lastReturnedStream = nil;
for (headerLen = 0; headerLen < 21;) {
if (_stream.atEndOfStream) {
if (headerLen == 0)
|
︙ | | | ︙ | |
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
}
entry = [[[OFLHAArchiveEntry alloc]
of_initWithHeader: header
stream: _stream
encoding: _encoding] autorelease];
_lastReturnedStream = [[OFLHAArchive_FileReadStream alloc]
of_initWithStream: _stream
entry: entry];
return entry;
}
- (OFStream <OFReadyForReadingObserving> *)streamForReadingCurrentEntry
{
if (_mode != OF_LHA_ARCHIVE_MODE_READ)
@throw [OFInvalidArgumentException exception];
if (_lastReturnedStream == nil)
@throw [OFInvalidArgumentException exception];
return [[(OFLHAArchive_FileReadStream *)_lastReturnedStream
retain] autorelease];
}
- (OFStream <OFReadyForWritingObserving> *)
streamForWritingEntry: (OFLHAArchiveEntry *)entry
{
OFString *compressionMethod;
|
|
|
|
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
}
entry = [[[OFLHAArchiveEntry alloc]
of_initWithHeader: header
stream: _stream
encoding: _encoding] autorelease];
_lastReturnedStream = [[OFLHAArchiveFileReadStream alloc]
of_initWithStream: _stream
entry: entry];
return entry;
}
- (OFStream <OFReadyForReadingObserving> *)streamForReadingCurrentEntry
{
if (_mode != OF_LHA_ARCHIVE_MODE_READ)
@throw [OFInvalidArgumentException exception];
if (_lastReturnedStream == nil)
@throw [OFInvalidArgumentException exception];
return [[(OFLHAArchiveFileReadStream *)_lastReturnedStream
retain] autorelease];
}
- (OFStream <OFReadyForWritingObserving> *)
streamForWritingEntry: (OFLHAArchiveEntry *)entry
{
OFString *compressionMethod;
|
︙ | | | ︙ | |
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
@throw [OFNotImplementedException exceptionWithSelector: _cmd
object: self];
[_lastReturnedStream close];
[_lastReturnedStream release];
_lastReturnedStream = nil;
_lastReturnedStream = [[OFLHAArchive_FileWriteStream alloc]
of_initWithStream: (OFSeekableStream *)_stream
entry: entry
encoding: _encoding];
return [[(OFLHAArchive_FileWriteStream *)_lastReturnedStream
retain] autorelease];
}
- (void)close
{
if (_stream == nil)
return;
[_lastReturnedStream close];
[_lastReturnedStream release];
_lastReturnedStream = nil;
[_stream release];
_stream = nil;
}
@end
@implementation OFLHAArchive_FileReadStream
- (instancetype)of_initWithStream: (OFStream *)stream
entry: (OFLHAArchiveEntry *)entry
{
self = [super init];
@try {
OFString *compressionMethod;
_stream = [stream retain];
compressionMethod = entry.compressionMethod;
if ([compressionMethod isEqual: @"-lh4-"] ||
[compressionMethod isEqual: @"-lh5-"])
_decompressedStream = [[OFLHAArchive_LHStream alloc]
of_initWithStream: stream
distanceBits: 4
dictionaryBits: 14];
else if ([compressionMethod isEqual: @"-lh6-"])
_decompressedStream = [[OFLHAArchive_LHStream alloc]
of_initWithStream: stream
distanceBits: 5
dictionaryBits: 16];
else if ([compressionMethod isEqual: @"-lh7-"])
_decompressedStream = [[OFLHAArchive_LHStream alloc]
of_initWithStream: stream
distanceBits: 5
dictionaryBits: 17];
else
_decompressedStream = [stream retain];
_entry = [entry copy];
|
|
|
|
|
|
|
|
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
@throw [OFNotImplementedException exceptionWithSelector: _cmd
object: self];
[_lastReturnedStream close];
[_lastReturnedStream release];
_lastReturnedStream = nil;
_lastReturnedStream = [[OFLHAArchiveFileWriteStream alloc]
of_initWithStream: (OFSeekableStream *)_stream
entry: entry
encoding: _encoding];
return [[(OFLHAArchiveFileWriteStream *)_lastReturnedStream
retain] autorelease];
}
- (void)close
{
if (_stream == nil)
return;
[_lastReturnedStream close];
[_lastReturnedStream release];
_lastReturnedStream = nil;
[_stream release];
_stream = nil;
}
@end
@implementation OFLHAArchiveFileReadStream
- (instancetype)of_initWithStream: (OFStream *)stream
entry: (OFLHAArchiveEntry *)entry
{
self = [super init];
@try {
OFString *compressionMethod;
_stream = [stream retain];
compressionMethod = entry.compressionMethod;
if ([compressionMethod isEqual: @"-lh4-"] ||
[compressionMethod isEqual: @"-lh5-"])
_decompressedStream = [[OFLHADecompressingStream alloc]
of_initWithStream: stream
distanceBits: 4
dictionaryBits: 14];
else if ([compressionMethod isEqual: @"-lh6-"])
_decompressedStream = [[OFLHADecompressingStream alloc]
of_initWithStream: stream
distanceBits: 5
dictionaryBits: 16];
else if ([compressionMethod isEqual: @"-lh7-"])
_decompressedStream = [[OFLHADecompressingStream alloc]
of_initWithStream: stream
distanceBits: 5
dictionaryBits: 17];
else
_decompressedStream = [stream retain];
_entry = [entry copy];
|
︙ | | | ︙ | |
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
|
toRead = _toRead;
/*
* Get the number of consumed bytes and directly read from the
* compressed stream, to make skipping much faster.
*/
if ([_decompressedStream isKindOfClass:
[OFLHAArchive_LHStream class]]) {
OFLHAArchive_LHStream *LHStream =
(OFLHAArchive_LHStream *)_decompressedStream;
[LHStream close];
toRead = _entry.compressedSize - LHStream->_bytesConsumed;
stream = _stream;
}
if ([stream isKindOfClass: [OFSeekableStream class]] &&
(sizeof(of_offset_t) > 4 || toRead < INT32_MAX))
[(OFSeekableStream *)stream seekToOffset: (of_offset_t)toRead
|
|
|
|
|
>
|
|
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
toRead = _toRead;
/*
* Get the number of consumed bytes and directly read from the
* compressed stream, to make skipping much faster.
*/
if ([_decompressedStream isKindOfClass:
[OFLHADecompressingStream class]]) {
OFLHADecompressingStream *decompressingStream =
(OFLHADecompressingStream *)_decompressedStream;
[decompressingStream close];
toRead =
_entry.compressedSize - decompressingStream->_bytesConsumed;
stream = _stream;
}
if ([stream isKindOfClass: [OFSeekableStream class]] &&
(sizeof(of_offset_t) > 4 || toRead < INT32_MAX))
[(OFSeekableStream *)stream seekToOffset: (of_offset_t)toRead
|
︙ | | | ︙ | |
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
[_decompressedStream release];
_decompressedStream = nil;
[super close];
}
@end
@implementation OFLHAArchive_FileWriteStream
- (instancetype)of_initWithStream: (OFSeekableStream *)stream
entry: (OFLHAArchiveEntry *)entry
encoding: (of_string_encoding_t)encoding
{
self = [super init];
@try {
|
|
|
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
|
[_decompressedStream release];
_decompressedStream = nil;
[super close];
}
@end
@implementation OFLHAArchiveFileWriteStream
- (instancetype)of_initWithStream: (OFSeekableStream *)stream
entry: (OFLHAArchiveEntry *)entry
encoding: (of_string_encoding_t)encoding
{
self = [super init];
@try {
|
︙ | | | ︙ | |