|
@@ -63,6 +63,8 @@ NSMutableDictionary *fileStreams = nil;
|
63
|
63
|
return assetURI;
|
64
|
64
|
}
|
65
|
65
|
|
|
66
|
+#pragma mark - system directories
|
|
67
|
+
|
66
|
68
|
+ (NSString *) getCacheDir {
|
67
|
69
|
return [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
|
68
|
70
|
}
|
|
@@ -98,6 +100,8 @@ NSMutableDictionary *fileStreams = nil;
|
98
|
100
|
return tempPath;
|
99
|
101
|
}
|
100
|
102
|
|
|
103
|
+#pragma mark - read asset stream
|
|
104
|
+
|
101
|
105
|
- (void) startAssetReadStream:(NSString *)assetUrl
|
102
|
106
|
{
|
103
|
107
|
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
|
|
@@ -185,6 +189,8 @@ NSMutableDictionary *fileStreams = nil;
|
185
|
189
|
}
|
186
|
190
|
}
|
187
|
191
|
|
|
192
|
+# pragma write file from file
|
|
193
|
+
|
188
|
194
|
+ (NSNumber *) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:(BOOL)append
|
189
|
195
|
{
|
190
|
196
|
NSInputStream * is = [[NSInputStream alloc] initWithFileAtPath:src];
|
|
@@ -205,6 +211,8 @@ NSMutableDictionary *fileStreams = nil;
|
205
|
211
|
return [NSNumber numberWithLong:written];
|
206
|
212
|
}
|
207
|
213
|
|
|
214
|
+# pragma mark - write file
|
|
215
|
+
|
208
|
216
|
+ (void) writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
|
209
|
217
|
{
|
210
|
218
|
@try {
|
|
@@ -226,14 +234,6 @@ NSMutableDictionary *fileStreams = nil;
|
226
|
234
|
NSData * content = nil;
|
227
|
235
|
if([encoding containsString:@"base64"]) {
|
228
|
236
|
content = [[NSData alloc] initWithBase64EncodedString:data options:0];
|
229
|
|
- if([encoding containsString:@"urlencode"])
|
230
|
|
- {
|
231
|
|
- NSString * decode = [[[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding] stringByRemovingPercentEncoding];
|
232
|
|
- if(decode != nil)
|
233
|
|
- {
|
234
|
|
- content = [decode dataUsingEncoding:NSUTF8StringEncoding];
|
235
|
|
- }
|
236
|
|
- }
|
237
|
237
|
}
|
238
|
238
|
else if([encoding isEqualToString:@"uri"]) {
|
239
|
239
|
NSNumber* size = [[self class] writeFileFromFile:data toFile:path append:append];
|
|
@@ -261,6 +261,8 @@ NSMutableDictionary *fileStreams = nil;
|
261
|
261
|
}
|
262
|
262
|
}
|
263
|
263
|
|
|
264
|
+# pragma mark - write file (array)
|
|
265
|
+
|
264
|
266
|
+ (void) writeFileArray:(NSString *)path data:(NSArray *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
|
265
|
267
|
@try {
|
266
|
268
|
NSFileManager * fm = [NSFileManager defaultManager];
|
|
@@ -303,6 +305,8 @@ NSMutableDictionary *fileStreams = nil;
|
303
|
305
|
}
|
304
|
306
|
}
|
305
|
307
|
|
|
308
|
+# pragma mark - read file
|
|
309
|
+
|
306
|
310
|
+ (void) readFile:(NSString *)path encoding:(NSString *)encoding
|
307
|
311
|
resolver:(RCTPromiseResolveBlock)resolve
|
308
|
312
|
rejecter:(RCTPromiseRejectBlock)reject
|
|
@@ -370,6 +374,8 @@ NSMutableDictionary *fileStreams = nil;
|
370
|
374
|
}
|
371
|
375
|
}
|
372
|
376
|
|
|
377
|
+# pragma mark - mkdir
|
|
378
|
+
|
373
|
379
|
+ (BOOL) mkdir:(NSString *) path {
|
374
|
380
|
BOOL isDir;
|
375
|
381
|
NSError * err = nil;
|
|
@@ -380,6 +386,8 @@ NSMutableDictionary *fileStreams = nil;
|
380
|
386
|
return err == nil;
|
381
|
387
|
}
|
382
|
388
|
|
|
389
|
+# pragma mark - stat
|
|
390
|
+
|
383
|
391
|
+ (NSDictionary *) stat:(NSString *) path error:(NSError **) error {
|
384
|
392
|
NSMutableDictionary *stat = [[NSMutableDictionary alloc] init];
|
385
|
393
|
BOOL isDir = NO;
|
|
@@ -401,6 +409,8 @@ NSMutableDictionary *fileStreams = nil;
|
401
|
409
|
};
|
402
|
410
|
}
|
403
|
411
|
|
|
412
|
+# pragma mark - exists
|
|
413
|
+
|
404
|
414
|
+ (BOOL) exists:(NSString *) path {
|
405
|
415
|
return [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:NULL];
|
406
|
416
|
}
|
|
@@ -422,6 +432,8 @@ NSMutableDictionary *fileStreams = nil;
|
422
|
432
|
return self;
|
423
|
433
|
}
|
424
|
434
|
|
|
435
|
+# pragma mark - open file stream
|
|
436
|
+
|
425
|
437
|
// Create file stream for write data
|
426
|
438
|
- (NSString *)openWithPath:(NSString *)destPath encode:(nullable NSString *)encode appendData:(BOOL)append {
|
427
|
439
|
self.outStream = [[NSOutputStream alloc] initToFileAtPath:destPath append:append];
|
|
@@ -434,6 +446,8 @@ NSMutableDictionary *fileStreams = nil;
|
434
|
446
|
return uuid;
|
435
|
447
|
}
|
436
|
448
|
|
|
449
|
+# pragma mark - file stream write chunk
|
|
450
|
+
|
437
|
451
|
// Write file chunk into an opened stream
|
438
|
452
|
- (void)writeEncodeChunk:(NSString *) chunk {
|
439
|
453
|
NSMutableData * decodedData = [NSData alloc];
|
|
@@ -679,6 +693,8 @@ NSMutableDictionary *fileStreams = nil;
|
679
|
693
|
|
680
|
694
|
}
|
681
|
695
|
|
|
696
|
+# pragma mark - get absolute path of resource
|
|
697
|
+
|
682
|
698
|
+ (void) getPathFromUri:(NSString *)uri completionHandler:(void(^)(NSString * path, ALAssetRepresentation *asset)) onComplete
|
683
|
699
|
{
|
684
|
700
|
if([uri hasPrefix:AL_PREFIX])
|