|
@@ -185,20 +185,24 @@ NSMutableDictionary *fileStreams = nil;
|
185
|
185
|
}
|
186
|
186
|
}
|
187
|
187
|
|
188
|
|
-+ (void) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:(BOOL)append
|
|
188
|
++ (NSNumber *) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:(BOOL)append
|
189
|
189
|
{
|
190
|
190
|
NSInputStream * is = [[NSInputStream alloc] initWithFileAtPath:src];
|
191
|
191
|
NSOutputStream * os = [[NSOutputStream alloc] initToFileAtPath:dest append:append];
|
192
|
192
|
[is open];
|
193
|
193
|
[os open];
|
194
|
194
|
uint8_t buffer[10240];
|
|
195
|
+ long written = 0;
|
195
|
196
|
int read = [is read:buffer maxLength:10240];
|
|
197
|
+ written += read;
|
196
|
198
|
while(read > 0) {
|
197
|
199
|
[os write:buffer maxLength:read];
|
198
|
200
|
read = [is read:buffer maxLength:10240];
|
|
201
|
+ written += read;
|
199
|
202
|
}
|
200
|
203
|
[os close];
|
201
|
204
|
[is close];
|
|
205
|
+ return [NSNumber numberWithLong:written];
|
202
|
206
|
}
|
203
|
207
|
|
204
|
208
|
+ (void) writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
|
|
@@ -225,8 +229,8 @@ NSMutableDictionary *fileStreams = nil;
|
225
|
229
|
content = [[NSData alloc] initWithBase64EncodedString:data options:0];
|
226
|
230
|
}
|
227
|
231
|
else if([encoding isEqualToString:@"uri"]) {
|
228
|
|
- [[self class] writeFileFromFile:data toFile:path append:append];
|
229
|
|
- resolve([NSNull null]);
|
|
232
|
+ NSNumber* size = [[self class] writeFileFromFile:data toFile:path append:append];
|
|
233
|
+ resolve(size);
|
230
|
234
|
return;
|
231
|
235
|
}
|
232
|
236
|
else {
|
|
@@ -241,7 +245,8 @@ NSMutableDictionary *fileStreams = nil;
|
241
|
245
|
[content writeToFile:path atomically:YES];
|
242
|
246
|
}
|
243
|
247
|
fm = nil;
|
244
|
|
- resolve([NSNull null]);
|
|
248
|
+
|
|
249
|
+ resolve([NSNumber numberWithInteger:[content length]]);
|
245
|
250
|
}
|
246
|
251
|
@catch (NSException * e)
|
247
|
252
|
{
|
|
@@ -283,7 +288,7 @@ NSMutableDictionary *fileStreams = nil;
|
283
|
288
|
}
|
284
|
289
|
free(bytes);
|
285
|
290
|
fm = nil;
|
286
|
|
- resolve([NSNull null]);
|
|
291
|
+ resolve([NSNumber numberWithInteger: data.count]);
|
287
|
292
|
}
|
288
|
293
|
@catch (NSException * e)
|
289
|
294
|
{
|