|
@@ -86,6 +86,7 @@ RCT_EXPORT_METHOD(fetchBlob:(NSDictionary *)options
|
86
|
86
|
}];
|
87
|
87
|
}
|
88
|
88
|
|
|
89
|
+#pragma mark - fs.createFile
|
89
|
90
|
RCT_EXPORT_METHOD(createFile:(NSString *)path data:(NSString *)data encoding:(NSString *)encoding callback:(RCTResponseSenderBlock)callback) {
|
90
|
91
|
|
91
|
92
|
NSFileManager * fm = [NSFileManager defaultManager];
|
|
@@ -112,7 +113,7 @@ RCT_EXPORT_METHOD(createFile:(NSString *)path data:(NSString *)data encoding:(NS
|
112
|
113
|
callback(@[[NSString stringWithFormat:@"failed to create new file at path %@ please ensure the folder exists"]]);
|
113
|
114
|
|
114
|
115
|
}
|
115
|
|
-
|
|
116
|
+#pragma mark - fs.createFileASCII
|
116
|
117
|
// method for create file with ASCII content
|
117
|
118
|
RCT_EXPORT_METHOD(createFileASCII:(NSString *)path data:(NSArray *)dataArray callback:(RCTResponseSenderBlock)callback) {
|
118
|
119
|
|
|
@@ -134,24 +135,22 @@ RCT_EXPORT_METHOD(createFileASCII:(NSString *)path data:(NSArray *)dataArray cal
|
134
|
135
|
|
135
|
136
|
}
|
136
|
137
|
|
137
|
|
-
|
|
138
|
+#pragma mark - fs.exists
|
138
|
139
|
RCT_EXPORT_METHOD(exists:(NSString *)path callback:(RCTResponseSenderBlock)callback) {
|
139
|
|
- BOOL isDir = NO;
|
140
|
|
- BOOL exists = NO;
|
141
|
|
- exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory: &isDir];
|
142
|
|
- callback(@[@(exists), @(isDir)]);
|
143
|
|
-
|
|
140
|
+ [RNFetchBlobFS exists:path callback:callback];
|
144
|
141
|
}
|
145
|
142
|
|
|
143
|
+#pragma mark - fs.writeFile
|
146
|
144
|
RCT_EXPORT_METHOD(writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
|
147
|
|
-
|
148
|
145
|
[RNFetchBlobFS writeFile:path encoding:[NSString stringWithString:encoding] data:data append:append resolver:resolve rejecter:reject];
|
149
|
146
|
})
|
150
|
147
|
|
|
148
|
+#pragma mark - fs.writeArray
|
151
|
149
|
RCT_EXPORT_METHOD(writeFileArray:(NSString *)path data:(NSArray *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
|
152
|
150
|
[RNFetchBlobFS writeFileArray:path data:data append:append resolver:resolve rejecter:reject];
|
153
|
151
|
})
|
154
|
152
|
|
|
153
|
+#pragma mark - fs.writeStream
|
155
|
154
|
RCT_EXPORT_METHOD(writeStream:(NSString *)path withEncoding:(NSString *)encoding appendData:(BOOL)append callback:(RCTResponseSenderBlock)callback) {
|
156
|
155
|
RNFetchBlobFS * fileStream = [[RNFetchBlobFS alloc] initWithBridgeRef:self.bridge];
|
157
|
156
|
NSFileManager * fm = [NSFileManager defaultManager];
|
|
@@ -165,6 +164,7 @@ RCT_EXPORT_METHOD(writeStream:(NSString *)path withEncoding:(NSString *)encoding
|
165
|
164
|
callback(@[[NSNull null], streamId]);
|
166
|
165
|
}
|
167
|
166
|
|
|
167
|
+#pragma mark - fs.writeArrayChunk
|
168
|
168
|
RCT_EXPORT_METHOD(writeArrayChunk:(NSString *)streamId withArray:(NSArray *)dataArray callback:(RCTResponseSenderBlock) callback) {
|
169
|
169
|
RNFetchBlobFS *fs = [[RNFetchBlobFS getFileStreams] valueForKey:streamId];
|
170
|
170
|
char * bytes = (char *) malloc([dataArray count]);
|
|
@@ -178,12 +178,14 @@ RCT_EXPORT_METHOD(writeArrayChunk:(NSString *)streamId withArray:(NSArray *)data
|
178
|
178
|
callback(@[[NSNull null]]);
|
179
|
179
|
}
|
180
|
180
|
|
|
181
|
+#pragma mark - fs.writeChunk
|
181
|
182
|
RCT_EXPORT_METHOD(writeChunk:(NSString *)streamId withData:(NSString *)data callback:(RCTResponseSenderBlock) callback) {
|
182
|
183
|
RNFetchBlobFS *fs = [[RNFetchBlobFS getFileStreams] valueForKey:streamId];
|
183
|
184
|
[fs writeEncodeChunk:data];
|
184
|
185
|
callback(@[[NSNull null]]);
|
185
|
186
|
}
|
186
|
187
|
|
|
188
|
+#pragma mark - fs.closeStream
|
187
|
189
|
RCT_EXPORT_METHOD(closeStream:(NSString *)streamId callback:(RCTResponseSenderBlock) callback) {
|
188
|
190
|
RNFetchBlobFS *fs = [[RNFetchBlobFS getFileStreams] valueForKey:streamId];
|
189
|
191
|
[fs closeOutStream];
|
|
@@ -200,6 +202,7 @@ RCT_EXPORT_METHOD(unlink:(NSString *)path callback:(RCTResponseSenderBlock) call
|
200
|
202
|
callback(@[[NSString stringWithFormat:@"failed to unlink file or path at %@", path]]);
|
201
|
203
|
}
|
202
|
204
|
|
|
205
|
+#pragma mark - fs.removeSession
|
203
|
206
|
RCT_EXPORT_METHOD(removeSession:(NSArray *)paths callback:(RCTResponseSenderBlock) callback) {
|
204
|
207
|
NSError * error = nil;
|
205
|
208
|
NSString * tmpPath = nil;
|
|
@@ -215,6 +218,7 @@ RCT_EXPORT_METHOD(removeSession:(NSArray *)paths callback:(RCTResponseSenderBloc
|
215
|
218
|
|
216
|
219
|
}
|
217
|
220
|
|
|
221
|
+#pragma mark - fs.ls
|
218
|
222
|
RCT_EXPORT_METHOD(ls:(NSString *)path callback:(RCTResponseSenderBlock) callback) {
|
219
|
223
|
NSFileManager* fm = [NSFileManager defaultManager];
|
220
|
224
|
BOOL exist = nil;
|
|
@@ -234,28 +238,46 @@ RCT_EXPORT_METHOD(ls:(NSString *)path callback:(RCTResponseSenderBlock) callback
|
234
|
238
|
|
235
|
239
|
}
|
236
|
240
|
|
237
|
|
-RCT_EXPORT_METHOD(stat:(NSString *)path callback:(RCTResponseSenderBlock) callback) {
|
238
|
|
- NSFileManager* fm = [NSFileManager defaultManager];
|
239
|
|
- BOOL exist = nil;
|
240
|
|
- BOOL isDir = nil;
|
241
|
|
- NSError * error = nil;
|
242
|
|
-
|
243
|
|
- path = [RNFetchBlobFS getPathOfAsset:path];
|
244
|
|
-
|
245
|
|
- exist = [fm fileExistsAtPath:path isDirectory:&isDir];
|
246
|
|
- if(exist == NO) {
|
247
|
|
- callback(@[[NSString stringWithFormat:@"failed to list path `%@` for it is not exist or it is not exist", path]]);
|
248
|
|
- return ;
|
249
|
|
- }
|
250
|
|
- NSData * res = [RNFetchBlobFS stat:path error:&error];
|
251
|
|
-
|
252
|
|
- if(error == nil)
|
253
|
|
- callback(@[[NSNull null], res]);
|
254
|
|
- else
|
255
|
|
- callback(@[[error localizedDescription], [NSNull null]]);
|
|
241
|
+#pragma mark - fs.stat
|
|
242
|
+RCT_EXPORT_METHOD(stat:(NSString *)target callback:(RCTResponseSenderBlock) callback) {
|
|
243
|
+
|
|
244
|
+ [RNFetchBlobFS getPathFromUri:target completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
|
|
245
|
+ __block NSMutableArray * result;
|
|
246
|
+ if(path != nil)
|
|
247
|
+ {
|
|
248
|
+ NSFileManager* fm = [NSFileManager defaultManager];
|
|
249
|
+ BOOL exist = nil;
|
|
250
|
+ BOOL isDir = nil;
|
|
251
|
+ NSError * error = nil;
|
|
252
|
+
|
|
253
|
+ exist = [fm fileExistsAtPath:path isDirectory:&isDir];
|
|
254
|
+ if(exist == NO) {
|
|
255
|
+ callback(@[[NSString stringWithFormat:@"failed to stat path `%@` for it is not exist or it is not exist", path]]);
|
|
256
|
+ return ;
|
|
257
|
+ }
|
|
258
|
+ result = [RNFetchBlobFS stat:path error:&error];
|
|
259
|
+
|
|
260
|
+ if(error == nil)
|
|
261
|
+ callback(@[[NSNull null], result]);
|
|
262
|
+ else
|
|
263
|
+ callback(@[[error localizedDescription], [NSNull null]]);
|
256
|
264
|
|
|
265
|
+ }
|
|
266
|
+ else if(asset != nil)
|
|
267
|
+ {
|
|
268
|
+ __block NSNumber * size = [NSNumber numberWithLong:[asset size]];
|
|
269
|
+ result = [asset metadata];
|
|
270
|
+ [result setValue:size forKey:@"size"];
|
|
271
|
+ callback(@[[NSNull null], result]);
|
|
272
|
+ }
|
|
273
|
+ else
|
|
274
|
+ {
|
|
275
|
+ callback(@[@"failed to stat path, could not resolve URI", [NSNull null]]);
|
|
276
|
+ }
|
|
277
|
+ }];
|
257
|
278
|
}
|
258
|
279
|
|
|
280
|
+#pragma mark - fs.lstat
|
259
|
281
|
RCT_EXPORT_METHOD(lstat:(NSString *)path callback:(RCTResponseSenderBlock) callback) {
|
260
|
282
|
NSFileManager* fm = [NSFileManager defaultManager];
|
261
|
283
|
BOOL exist = nil;
|
|
@@ -289,6 +311,7 @@ RCT_EXPORT_METHOD(lstat:(NSString *)path callback:(RCTResponseSenderBlock) callb
|
289
|
311
|
|
290
|
312
|
}
|
291
|
313
|
|
|
314
|
+#pragma mark - fs.cp
|
292
|
315
|
RCT_EXPORT_METHOD(cp:(NSString*)src toPath:(NSString *)dest callback:(RCTResponseSenderBlock) callback) {
|
293
|
316
|
|
294
|
317
|
// path = [RNFetchBlobFS getPathOfAsset:path];
|
|
@@ -312,6 +335,8 @@ RCT_EXPORT_METHOD(cp:(NSString*)src toPath:(NSString *)dest callback:(RCTRespons
|
312
|
335
|
|
313
|
336
|
}
|
314
|
337
|
|
|
338
|
+
|
|
339
|
+#pragma mark - fs.mv
|
315
|
340
|
RCT_EXPORT_METHOD(mv:(NSString *)path toPath:(NSString *)dest callback:(RCTResponseSenderBlock) callback) {
|
316
|
341
|
NSError * error = nil;
|
317
|
342
|
BOOL result = [[NSFileManager defaultManager] moveItemAtURL:[NSURL fileURLWithPath:path] toURL:[NSURL fileURLWithPath:dest] error:&error];
|
|
@@ -323,8 +348,9 @@ RCT_EXPORT_METHOD(mv:(NSString *)path toPath:(NSString *)dest callback:(RCTRespo
|
323
|
348
|
|
324
|
349
|
}
|
325
|
350
|
|
|
351
|
+#pragma mark - fs.mkdir
|
326
|
352
|
RCT_EXPORT_METHOD(mkdir:(NSString *)path callback:(RCTResponseSenderBlock) callback) {
|
327
|
|
- if([RNFetchBlobFS exists:path]) {
|
|
353
|
+ if([[NSFileManager defaultManager] fileExistsAtPath:path]) {
|
328
|
354
|
callback(@[@"mkdir failed, folder already exists"]);
|
329
|
355
|
return;
|
330
|
356
|
}
|
|
@@ -333,11 +359,13 @@ RCT_EXPORT_METHOD(mkdir:(NSString *)path callback:(RCTResponseSenderBlock) callb
|
333
|
359
|
callback(@[[NSNull null]]);
|
334
|
360
|
}
|
335
|
361
|
|
|
362
|
+#pragma mark - fs.readFile
|
336
|
363
|
RCT_EXPORT_METHOD(readFile:(NSString *)path encoding:(NSString *)encoding resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
|
337
|
364
|
|
338
|
365
|
[RNFetchBlobFS readFile:path encoding:encoding resolver:resolve rejecter:reject onComplete:nil];
|
339
|
366
|
})
|
340
|
367
|
|
|
368
|
+#pragma mark - fs.readStream
|
341
|
369
|
RCT_EXPORT_METHOD(readStream:(NSString *)path withEncoding:(NSString *)encoding bufferSize:(int)bufferSize) {
|
342
|
370
|
|
343
|
371
|
RNFetchBlobFS *fileStream = [[RNFetchBlobFS alloc] initWithBridgeRef:self.bridge];
|
|
@@ -351,6 +379,7 @@ RCT_EXPORT_METHOD(readStream:(NSString *)path withEncoding:(NSString *)encoding
|
351
|
379
|
[fileStream readWithPath:path useEncoding:encoding bufferSize:bufferSize];
|
352
|
380
|
}
|
353
|
381
|
|
|
382
|
+#pragma mark - fs.getEnvionmentDirs
|
354
|
383
|
RCT_EXPORT_METHOD(getEnvironmentDirs:(RCTResponseSenderBlock) callback) {
|
355
|
384
|
|
356
|
385
|
callback(@[
|
|
@@ -359,20 +388,24 @@ RCT_EXPORT_METHOD(getEnvironmentDirs:(RCTResponseSenderBlock) callback) {
|
359
|
388
|
]);
|
360
|
389
|
}
|
361
|
390
|
|
|
391
|
+#pragma mark - net.cancelRequest
|
362
|
392
|
RCT_EXPORT_METHOD(cancelRequest:(NSString *)taskId callback:(RCTResponseSenderBlock)callback) {
|
363
|
393
|
[RNFetchBlobNetwork cancelRequest:taskId];
|
364
|
394
|
callback(@[[NSNull null], taskId]);
|
365
|
395
|
|
366
|
396
|
}
|
367
|
397
|
|
|
398
|
+#pragma mark - net.enableProgressReport
|
368
|
399
|
RCT_EXPORT_METHOD(enableProgressReport:(NSString *)taskId {
|
369
|
400
|
[RNFetchBlobNetwork enableProgressReport:taskId];
|
370
|
401
|
})
|
371
|
402
|
|
|
403
|
+#pragma mark - net.enableUploadProgressReport
|
372
|
404
|
RCT_EXPORT_METHOD(enableUploadProgressReport:(NSString *)taskId {
|
373
|
405
|
[RNFetchBlobNetwork enableUploadProgress:taskId];
|
374
|
406
|
})
|
375
|
407
|
|
|
408
|
+#pragma mark - fs.slice
|
376
|
409
|
RCT_EXPORT_METHOD(slice:(NSString *)src dest:(NSString *)dest start:(nonnull NSNumber *)start end:(nonnull NSNumber *)end resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
|
377
|
410
|
{
|
378
|
411
|
[RNFetchBlobFS slice:src dest:dest start:start end:end encode:@"" resolver:resolve rejecter:reject];
|