forked from libgit2/objective-git
/
GTOdbObject.m
63 lines (43 loc) · 1.09 KB
/
GTOdbObject.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
57
58
59
60
61
62
63
//
// GTOdbObject.m
// ObjectiveGitFramework
//
// Created by Timothy Clem on 3/23/11.
// Copyright 2011 GitHub, Inc. All rights reserved.
//
#import "GTOdbObject.h"
#import "GTLib.h"
#import "NSString+Git.h"
@interface GTOdbObject()
@property (nonatomic, assign) git_odb_object *odbObject;
@end
@implementation GTOdbObject
#pragma mark API
@synthesize odbObject;
- (id)initWithObject:(git_odb_object *)object {
if((self = [super init])) {
self.odbObject = object;
}
return self;
}
+ (id)objectWithObject:(git_odb_object *)object {
return [[[self alloc] initWithObject:object] autorelease];
}
- (NSString *)hash {
return [GTLib convertOidToSha:git_odb_object_id(self.odbObject)];
}
- (GTObjectType)type {
return git_odb_object_type(self.odbObject);
}
- (NSUInteger)length {
return git_odb_object_size(self.odbObject);
}
- (NSData *)data {
return [NSData dataWithBytes:git_odb_object_data(self.odbObject) length:[self length]];
}
- (NSString *)dataAsUTF8String {
NSData *data = [self data];
if(!data) return nil;
return [NSString stringWithUTF8String:[data bytes]];
}
@end