-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathObjGitObject.m
56 lines (45 loc) · 1.15 KB
/
ObjGitObject.m
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
52
53
54
55
56
//
// ObjGitObject.m
// ObjGit
//
#import "ObjGitObject.h"
#import "NSDataCompression.h"
@implementation ObjGitObject
@synthesize sha;
@synthesize size;
@synthesize type;
@synthesize contents;
@synthesize raw;
@synthesize rawContents;
@synthesize rawContentLen;
- (id) initFromRaw:(NSData *)rawData withSha:(NSString *)shaValue
{
self = [super init];
sha = shaValue;
raw = [self inflateRaw:rawData];
// NSLog(@"init sha: %@", sha);
// NSLog(@"raw: %@", raw);
[self parseRaw];
return self;
}
- (void) parseRaw
{
char *ptr, *bytes = (char *)[raw bytes];
int len, rest;
len = (ptr = memchr(bytes, nil, len = [raw length])) ? ptr - bytes : len;
rest = [raw length] - len - 1;
ptr++;
NSString *header = [NSString stringWithCString:bytes length:len];
contents = [NSString stringWithCString:ptr length:rest];
rawContents = malloc(rest);
memcpy(rawContents, ptr, rest);
rawContentLen = rest;
NSArray *headerData = [header componentsSeparatedByString:@" "];
type = [headerData objectAtIndex:0];
size = [[headerData objectAtIndex:1] intValue];
}
- (NSData *) inflateRaw:(NSData *)rawData
{
return [rawData decompressedData];
}
@end