File: XADCompressParser.m

package info (click to toggle)
unar 1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,664 kB
  • sloc: ansic: 52,939; objc: 39,563; cpp: 4,074; makefile: 99; perl: 10
file content (51 lines) | stat: -rw-r--r-- 1,465 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
#import "XADCompressParser.h"
#import "XADCompressHandle.h"


@implementation XADCompressParser

+(int)requiredHeaderSize { return 3; }

+(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name
{
	int length=[data length];
	const uint8_t *bytes=[data bytes];

	return length>=3&&bytes[0]==0x1f&&bytes[1]==0x9d;
}

-(void)parse
{
	CSHandle *fh=[self handle];

	[fh skipBytes:2];
	int flags=[fh readUInt8];

	NSString *name=[[self name] stringByDeletingPathExtension];

	NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithObjectsAndKeys:
		[self XADPathWithUnseparatedString:name],XADFileNameKey,
		[self XADStringWithString:@"Compress"],XADCompressionNameKey,
		[NSNumber numberWithLongLong:3],XADDataOffsetKey,
		[NSNumber numberWithInt:flags],@"CompressFlags",
	nil];

	if([name matchedByPattern:@"\\.(tar|cpio)" options:REG_ICASE])
	[dict setObject:[NSNumber numberWithBool:YES] forKey:XADIsArchiveKey];

	off_t size=[[self handle] fileSize];
	if(size!=CSHandleMaxLength)
	[dict setObject:[NSNumber numberWithLongLong:size-3] forKey:XADCompressedSizeKey];

	[self addEntryWithDictionary:dict];
}

-(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum
{
	return [[[XADCompressHandle alloc] initWithHandle:[self handleAtDataOffsetForDictionary:dict]
	flags:[[dict objectForKey:@"CompressFlags"] intValue]] autorelease];
}

-(NSString *)formatName { return @"Compress"; }

@end