ObjFW  Check-in [1a6e3816c1]

Overview
Comment:OFLHAArchiveEntry: Keep the method as a string

It is only necessary to extract files, so it makes sense to keep it as
is to be able to list files using an unknown method.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1a6e3816c1f3be771780bb22a21867702b322d9f2da063f870e49d6247604cff
User & Date: js on 2018-05-27 07:32:22
Other Links: manifest | tags
Context
2018-05-27
09:44
ofzip: Add support for LHA archives check-in: c693041e37 user: js tags: trunk
07:32
OFLHAArchiveEntry: Keep the method as a string check-in: 1a6e3816c1 user: js tags: trunk
00:48
OFLHAArchiveEntry: Improve directory name parsing check-in: 5c4470fb42 user: js tags: trunk
Changes

Modified src/OFLHAArchive.m from [d7dfa4dbcd] to [dc06a91f23].

177
178
179
180
181
182
183
184
185

186
187
188
189
190
191
192
@implementation OFLHAArchive_FileReadStream
- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFLHAArchiveEntry *)entry
{
	self = [super init];

	@try {
		if ([entry method] != OF_LHA_ARCHIVE_ENTRY_METHOD_LH0 &&
		    [entry method] != OF_LHA_ARCHIVE_ENTRY_METHOD_LHD)

			@throw [OFNotImplementedException
			    exceptionWithSelector: _cmd
					   object: self];

		_entry = [entry copy];
		_stream = [stream retain];
		_toRead = [entry uncompressedSize];







|
|
>







177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
@implementation OFLHAArchive_FileReadStream
- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFLHAArchiveEntry *)entry
{
	self = [super init];

	@try {
		OFString *method = [entry method];

		if (![method isEqual: @"-lh0-"] && ![method isEqual: @"-lhd-"])
			@throw [OFNotImplementedException
			    exceptionWithSelector: _cmd
					   object: self];

		_entry = [entry copy];
		_stream = [stream retain];
		_toRead = [entry uncompressedSize];

Modified src/OFLHAArchiveEntry.h from [d20f4f4531] to [7d4437acfc].

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
63
64
65
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

OF_ASSUME_NONNULL_BEGIN

@class OFArray OF_GENERIC(ObjectType);
@class OFData;
@class OFDate;
@class OFNumber;

/*! @file */

/*!
 * @brief The compression method of the archive entry.
 */
typedef enum of_lha_archive_method_t {
	/*! No compression */
	OF_LHA_ARCHIVE_ENTRY_METHOD_LH0,
	OF_LHA_ARCHIVE_ENTRY_METHOD_LZS,
	OF_LHA_ARCHIVE_ENTRY_METHOD_LZ4,
	OF_LHA_ARCHIVE_ENTRY_METHOD_LH1,
	OF_LHA_ARCHIVE_ENTRY_METHOD_LH2,
	OF_LHA_ARCHIVE_ENTRY_METHOD_LH3,
	OF_LHA_ARCHIVE_ENTRY_METHOD_LH4,
	OF_LHA_ARCHIVE_ENTRY_METHOD_LH5,
	OF_LHA_ARCHIVE_ENTRY_METHOD_LH6,
	OF_LHA_ARCHIVE_ENTRY_METHOD_LH7,
	OF_LHA_ARCHIVE_ENTRY_METHOD_LH8,
	/*! Directory */
	OF_LHA_ARCHIVE_ENTRY_METHOD_LHD
} of_lha_archive_method_t;

/*!
 * @class OFLHAArchiveEntry OFLHAArchiveEntry.h ObjFW/OFLHAArchiveEntry.h
 *
 * @brief A class which represents an entry in the central directory of a LHA
 *	  archive.
 */
@interface OFLHAArchiveEntry: OFObject <OFCopying>
{
#ifdef OF_LHA_ARCHIVE_ENTRY_M
@public
#endif
	of_lha_archive_method_t _method;
	OFString *_fileName, *_Nullable _directoryName;
	uint32_t _compressedSize, _uncompressedSize;
	OFDate *_date;
	uint8_t _level;
	uint16_t _CRC16;
	uint8_t _operatingSystemIdentifier;
	OFString *_Nullable _fileComment;
	OFNumber *_Nullable _mode, *_Nullable _UID, *_Nullable _GID;
	OFString *_Nullable _owner, *_Nullable _group;
	OFDate *_Nullable _modificationDate;
	OFArray OF_GENERIC(OFData *) *_extensions;
}

/*!
 * @brief The method of the entry.
 */
@property (readonly, nonatomic) of_lha_archive_method_t method;

/*!
 * @brief The file name of the entry.
 */
@property (readonly, copy, nonatomic) OFString *fileName;






/*!
 * @brief The compressed size of the entry's file.
 */
@property (readonly, nonatomic) uint32_t compressedSize;

/*!
 * @brief The uncompressed size of the entry's file.







|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<












<
|












<
<
<
<
<





>
>
>
>
>







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
63
64
65
66
67
68

OF_ASSUME_NONNULL_BEGIN

@class OFArray OF_GENERIC(ObjectType);
@class OFData;
@class OFDate;
@class OFNumber;
@class OFString;






















/*!
 * @class OFLHAArchiveEntry OFLHAArchiveEntry.h ObjFW/OFLHAArchiveEntry.h
 *
 * @brief A class which represents an entry in the central directory of a LHA
 *	  archive.
 */
@interface OFLHAArchiveEntry: OFObject <OFCopying>
{
#ifdef OF_LHA_ARCHIVE_ENTRY_M
@public
#endif

	OFString *_fileName, *_Nullable _directoryName, *_method;
	uint32_t _compressedSize, _uncompressedSize;
	OFDate *_date;
	uint8_t _level;
	uint16_t _CRC16;
	uint8_t _operatingSystemIdentifier;
	OFString *_Nullable _fileComment;
	OFNumber *_Nullable _mode, *_Nullable _UID, *_Nullable _GID;
	OFString *_Nullable _owner, *_Nullable _group;
	OFDate *_Nullable _modificationDate;
	OFArray OF_GENERIC(OFData *) *_extensions;
}






/*!
 * @brief The file name of the entry.
 */
@property (readonly, copy, nonatomic) OFString *fileName;

/*!
 * @brief The method of the entry.
 */
@property (readonly, copy, nonatomic) OFString *method;

/*!
 * @brief The compressed size of the entry's file.
 */
@property (readonly, nonatomic) uint32_t compressedSize;

/*!
 * @brief The uncompressed size of the entry's file.

Modified src/OFLHAArchiveEntry.m from [e8d94333d8] to [596d16c180].

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
289
290
291

		if (headerSize < 21)
			@throw [OFInvalidFormatException exception];

		[stream readIntoBuffer: header
			   exactLength: 20];

		if (memcmp(header + 1, "-lh0-", 5) == 0)
			_method = OF_LHA_ARCHIVE_ENTRY_METHOD_LH0;
		else if (memcmp(header + 1, "-lzs-", 5) == 0)
			_method = OF_LHA_ARCHIVE_ENTRY_METHOD_LZS;
		else if (memcmp(header + 1, "-lz4-", 5) == 0)
			_method = OF_LHA_ARCHIVE_ENTRY_METHOD_LZ4;
		else if (memcmp(header + 1, "-lh1-", 5) == 0)
			_method = OF_LHA_ARCHIVE_ENTRY_METHOD_LH1;
		else if (memcmp(header + 1, "-lh2-", 5) == 0)
			_method = OF_LHA_ARCHIVE_ENTRY_METHOD_LH2;
		else if (memcmp(header + 1, "-lh3-", 5) == 0)
			_method = OF_LHA_ARCHIVE_ENTRY_METHOD_LH3;
		else if (memcmp(header + 1, "-lh4-", 5) == 0)
			_method = OF_LHA_ARCHIVE_ENTRY_METHOD_LH4;
		else if (memcmp(header + 1, "-lh5-", 5) == 0)
			_method = OF_LHA_ARCHIVE_ENTRY_METHOD_LH5;
		else if (memcmp(header + 1, "-lh6-", 5) == 0)
			_method = OF_LHA_ARCHIVE_ENTRY_METHOD_LH6;
		else if (memcmp(header + 1, "-lh7-", 5) == 0)
			_method = OF_LHA_ARCHIVE_ENTRY_METHOD_LH7;
		else if (memcmp(header + 1, "-lh8-", 5) == 0)
			_method = OF_LHA_ARCHIVE_ENTRY_METHOD_LH8;
		else if (memcmp(header + 1, "-lhd-", 5) == 0)
			_method = OF_LHA_ARCHIVE_ENTRY_METHOD_LHD;
		else {
			OFString *version = [OFString
			    stringWithCString: header + 1
				     encoding: OF_STRING_ENCODING_ASCII
				       length: 5];

			@throw [OFUnsupportedVersionException
			    exceptionWithVersion: version];
		}

		memcpy(&_compressedSize, header + 6, 4);
		_compressedSize = OF_BSWAP32_IF_BE(_compressedSize);

		memcpy(&_uncompressedSize, header + 10, 4);
		_uncompressedSize = OF_BSWAP32_IF_BE(_uncompressedSize);








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
|
<
<
<
<







245
246
247
248
249
250
251

























252
253
254
255




256
257
258
259
260
261
262

		if (headerSize < 21)
			@throw [OFInvalidFormatException exception];

		[stream readIntoBuffer: header
			   exactLength: 20];


























		_method = [[OFString alloc]
		    initWithCString: header + 1
			   encoding: OF_STRING_ENCODING_ASCII
			     length: 5];





		memcpy(&_compressedSize, header + 6, 4);
		_compressedSize = OF_BSWAP32_IF_BE(_compressedSize);

		memcpy(&_uncompressedSize, header + 10, 4);
		_uncompressedSize = OF_BSWAP32_IF_BE(_uncompressedSize);

329
330
331
332
333
334
335

336
337
338
339
340
341
342
	}

	return self;
}

- (void)dealloc
{

	[_fileName release];
	[_directoryName release];
	[_date release];
	[_fileComment release];
	[_mode release];
	[_UID release];
	[_GID release];







>







300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
	}

	return self;
}

- (void)dealloc
{
	[_method release];
	[_fileName release];
	[_directoryName release];
	[_date release];
	[_fileComment release];
	[_mode release];
	[_UID release];
	[_GID release];
368
369
370
371
372
373
374

375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390

391
392
393
394
395
396
397
398
399
400
	    : [OFString stringWithFormat: @"%" PRIo16, [_mode uInt16Value]]);
	OFString *extensions = [[_extensions description]
	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];
	OFString *ret = [OFString stringWithFormat:
	    @"<%@:\n"
	    @"\tFile name = %@\n"

	    @"\tCompressed size = %" @PRIu32 "\n"
	    @"\tUncompressed size = %" @PRIu32 "\n"
	    @"\tDate = %@\n"
	    @"\tLevel = %u\n"
	    @"\tCRC16 = %04" @PRIX16 @"\n"
	    @"\tOperating system identifier = %c\n"
	    @"\tComment = %@\n"
	    @"\tMode = %@\n"
	    @"\tUID = %@\n"
	    @"\tGID = %@\n"
	    @"\tOwner = %@\n"
	    @"\tGroup = %@\n"
	    @"\tModification date = %@\n"
	    @"\tExtensions: %@"
	    @">",
	    [self class], [self fileName], _compressedSize, _uncompressedSize,

	    _date, _level, _CRC16, _operatingSystemIdentifier, _fileComment,
	    mode, _UID, _GID, _owner, _group, _modificationDate, extensions];

	[ret retain];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}
@end







>















|
>
|
|








340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
	    : [OFString stringWithFormat: @"%" PRIo16, [_mode uInt16Value]]);
	OFString *extensions = [[_extensions description]
	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];
	OFString *ret = [OFString stringWithFormat:
	    @"<%@:\n"
	    @"\tFile name = %@\n"
	    @"\tMethod = %@\n"
	    @"\tCompressed size = %" @PRIu32 "\n"
	    @"\tUncompressed size = %" @PRIu32 "\n"
	    @"\tDate = %@\n"
	    @"\tLevel = %u\n"
	    @"\tCRC16 = %04" @PRIX16 @"\n"
	    @"\tOperating system identifier = %c\n"
	    @"\tComment = %@\n"
	    @"\tMode = %@\n"
	    @"\tUID = %@\n"
	    @"\tGID = %@\n"
	    @"\tOwner = %@\n"
	    @"\tGroup = %@\n"
	    @"\tModification date = %@\n"
	    @"\tExtensions: %@"
	    @">",
	    [self class], [self fileName], _method, _compressedSize,
	    _uncompressedSize, _date, _level, _CRC16,
	    _operatingSystemIdentifier, _fileComment, mode, _UID, _GID, _owner,
	    _group, _modificationDate, extensions];

	[ret retain];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}
@end