forked from SVGKit/SVGKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSVGKSourceLocalFile.m
More file actions
40 lines (31 loc) · 1.11 KB
/
Copy pathSVGKSourceLocalFile.m
File metadata and controls
40 lines (31 loc) · 1.11 KB
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
#import "SVGKSourceLocalFile.h"
@implementation SVGKSourceLocalFile
+(uint64_t) sizeInBytesOfFilePath:(NSString*) filePath
{
NSError* errorReadingFileAttributes;
NSFileManager* fileManager = [NSFileManager defaultManager];
NSDictionary* atts = [fileManager attributesOfItemAtPath:filePath error:&errorReadingFileAttributes];
if( atts == nil )
return -1;
else
return atts.fileSize;
}
+ (SVGKSourceLocalFile*)sourceFromFilename:(NSString*)p {
NSInputStream* stream = [NSInputStream inputStreamWithFileAtPath:p];
[stream open];
SVGKSourceLocalFile* s = [[[SVGKSourceLocalFile alloc] initWithInputSteam:stream] autorelease];
s.filePath = p;
s.approximateLengthInBytesOr0 = [self sizeInBytesOfFilePath:p];
return s;
}
- (SVGKSource *)sourceFromRelativePath:(NSString *)relative {
NSString *absolute = [[self.filePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:relative];
if ([[NSFileManager defaultManager] fileExistsAtPath:absolute])
return [SVGKSourceLocalFile sourceFromFilename:absolute];
return nil;
}
- (void)dealloc {
self.filePath = nil;
[super dealloc];
}
@end