forked from mykeepass/KeePassLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WrapperNSData.m
63 lines (49 loc) · 1.17 KB
/
WrapperNSData.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
//
// WrapperNSData.m
// KeePass2
//
// Created by Qiang Yu on 1/10/10.
// Copyright 2010 Qiang Yu. All rights reserved.
//
#import "WrapperNSData.h"
@implementation WrapperNSData
-initWithContentsOfMappedFile:(NSString *)filename{
if(self=[super init]){
_nsdata = [[NSData alloc]initWithContentsOfMappedFile:filename];
}
return self;
}
-initWithNSData:(NSData *)data{
if(self=[super init]){
_nsdata = [data retain];
}
return self;
}
-(void)dealloc{
[_nsdata dealloc];
[super dealloc];
}
-(NSUInteger)readBytes:(void *)buffer length:(NSUInteger)length{
NSRange range;
range.location = _offset;
range.length = MIN([_nsdata length]-_offset, length);
if(range.length) [_nsdata getBytes:buffer range:range];
_offset += range.length;
return range.length;
}
-(NSUInteger)lengthOfRemainingReadbleBytes{
return [_nsdata length]-_offset;
}
-(uint8_t *)getRemainingBufferToRead{
return (uint8_t *)[_nsdata bytes]+_offset;
}
-(NSUInteger)setReadOffset:(NSUInteger) offset{
if(offset>[_nsdata length]) offset=[_nsdata length];
_offset = offset;
return _offset;
}
-(NSUInteger)moveReadOffset:(NSInteger) offset{
[self setReadOffset:_offset+offset];
return _offset;
}
@end