-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathORBinaryData.m
214 lines (166 loc) · 5.56 KB
/
ORBinaryData.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//
// ORBinaryData.m
//
// Created by William Castrogiovanni on 6/17/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "ORBinaryData.h"
@implementation ORBinaryData
@synthesize contentId;
@synthesize MIMEType;
@synthesize fileName;
- (id) init {
if ((self = [super init])) {
// Create the Embedded Data object around which these
// class methods wrap
_embeddedData = [[NSData allocWithZone:[self zone]] init];
[self OR_initMetaData];
}
return self;
}
- (void) OR_initMetaData {
MIMEType = @"application/octet-stream";
}
-(void) dealloc {
[contentId release];
[MIMEType release];
[fileName release];
[_embeddedData release];
[super dealloc];
}
#pragma mark -
#pragma mark NSData Wrapper Methods
- (NSUInteger)length {
return [_embeddedData length];
}
- (const void *)bytes{
return [_embeddedData bytes];
}
#pragma mark -
#pragma mark NSData (NSExtendedData) Wrapper Methods
- (NSString *)description{
return [_embeddedData description];
}
- (void)getBytes:(void *)buffer{
return [_embeddedData getBytes:buffer];
}
- (void)getBytes:(void *)buffer length:(NSUInteger)length{
return [_embeddedData getBytes:buffer length:length];
}
- (void)getBytes:(void *)buffer range:(NSRange)range{
return [_embeddedData getBytes:buffer range:range];
}
- (BOOL)isEqualToData:(NSData *)other{
return [_embeddedData isEqualToData:other];
}
- (NSData *)subdataWithRange:(NSRange)range{
return [_embeddedData subdataWithRange:range];
}
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile{
return [_embeddedData writeToFile:path atomically:useAuxiliaryFile];
}
- (BOOL)writeToURL:(NSURL *)url atomically:(BOOL)atomically{
return [_embeddedData writeToURL:url atomically:atomically];
}
- (BOOL)writeToFile:(NSString *)path options:(NSUInteger)writeOptionsMask error:(NSError **)errorPtr{
return [_embeddedData writeToFile:path options:writeOptionsMask error:errorPtr];
}
- (BOOL)writeToURL:(NSURL *)url options:(NSUInteger)writeOptionsMask error:(NSError **)errorPtr{
return [_embeddedData writeToURL:url options:writeOptionsMask error:errorPtr];
}
#pragma mark -
#pragma mark NSData (NSDataCreation) Wrapper Methods
+ (id)data{
return [NSData data];
}
+ (id)dataWithBytes:(const void *)bytes length:(NSUInteger)length{
return [NSData dataWithBytes:bytes length:length];
}
+ (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length {
return [NSData dataWithBytesNoCopy:bytes length:length];
}
+ (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b{
return [NSData dataWithBytesNoCopy:bytes length:length freeWhenDone:b];
}
+ (id)dataWithContentsOfFile:(NSString *)path options:(NSUInteger)readOptionsMask error:(NSError **)errorPtr{
return [NSData dataWithContentsOfFile:path options:readOptionsMask error:errorPtr];
}
+ (id)dataWithContentsOfURL:(NSURL *)url options:(NSUInteger)readOptionsMask error:(NSError **)errorPtr{
return [NSData dataWithContentsOfURL:url options:readOptionsMask error:errorPtr];
}
+ (id)dataWithContentsOfFile:(NSString *)path {
return [NSData dataWithContentsOfFile:path];
}
+ (id)dataWithContentsOfURL:(NSURL *)url {
return [NSData dataWithContentsOfURL:url];
}
+ (id)dataWithContentsOfMappedFile:(NSString *)path {
return [NSData dataWithContentsOfMappedFile:path];
}
- (id)initWithBytes:(const void *)bytes length:(NSUInteger)length {
if ((self = [super init])) {
_embeddedData = [[NSData allocWithZone:[self zone]] initWithBytes:bytes length:length];
}
[self OR_initMetaData];
return self;
}
- (id)initWithBytesNoCopy:(void *)bytes length:(NSUInteger)length {
if ((self = [super init])) {
_embeddedData = [[NSData allocWithZone:[self zone]] initWithBytesNoCopy:bytes length:length];
}
[self OR_initMetaData];
return self;
}
- (id)initWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b {
if ((self = [super init])) {
_embeddedData = [[NSData allocWithZone:[self zone]] initWithBytesNoCopy:bytes length:length freeWhenDone:b];
}
[self OR_initMetaData];
return self;
}
- (id)initWithContentsOfFile:(NSString *)path options:(NSUInteger)readOptionsMask error:(NSError **)errorPtr {
if ((self = [super init])) {
_embeddedData = [[NSData allocWithZone:[self zone]] initWithContentsOfFile:path options:readOptionsMask error:errorPtr];
}
[self OR_initMetaData];
return self;
}
- (id)initWithContentsOfURL:(NSURL *)url options:(NSUInteger)readOptionsMask error:(NSError **)errorPtr {
if ((self = [super init])) {
_embeddedData = [[NSData allocWithZone:[self zone]] initWithContentsOfURL:url options:readOptionsMask error:errorPtr];
}
[self OR_initMetaData];
return self;
}
- (id)initWithContentsOfFile:(NSString *)path {
if ((self = [super init])) {
_embeddedData = [[NSData allocWithZone:[self zone]] initWithContentsOfFile:path];
}
[self OR_initMetaData];
return self;
}
- (id)initWithContentsOfURL:(NSURL *)url {
if ((self = [super init])) {
_embeddedData = [[NSData allocWithZone:[self zone]] initWithContentsOfURL:url];
}
[self OR_initMetaData];
return self;
}
- (id)initWithContentsOfMappedFile:(NSString *)path {
if ((self = [super init])) {
_embeddedData = [[NSData allocWithZone:[self zone]] initWithContentsOfMappedFile:path];
}
[self OR_initMetaData];
return self;
}
- (id)initWithData:(NSData *)data {
if ((self = [super init])) {
_embeddedData = [[NSData allocWithZone:[self zone]] initWithData:data];
}
[self OR_initMetaData];
return self;
}
+ (id)dataWithData:(NSData *)data {
return [NSData dataWithData:data];
}
@end