1515
1616
1717RCTBridge * bridgeRef;
18+ dispatch_queue_t commonTaskQueue;
19+ dispatch_queue_t fsQueue;
1820
1921// //////////////////////////////////////
2022//
@@ -30,7 +32,9 @@ @implementation RNFetchBlob
3032@synthesize bridge = _bridge;
3133
3234- (dispatch_queue_t ) methodQueue {
33- return dispatch_queue_create (" RNFetchBlob.queue" , DISPATCH_QUEUE_SERIAL);
35+ if (commonTaskQueue == nil )
36+ commonTaskQueue = dispatch_queue_create (" RNFetchBlob.queue" , DISPATCH_QUEUE_SERIAL);
37+ return commonTaskQueue;
3438}
3539
3640+ (RCTBridge *)getRCTBridge
@@ -43,6 +47,10 @@ + (RCTBridge *)getRCTBridge
4347- (id ) init {
4448 self = [super init ];
4549 self.filePathPrefix = FILE_PREFIX;
50+ if (commonTaskQueue == nil )
51+ commonTaskQueue = dispatch_queue_create (" RNFetchBlob.queue" , DISPATCH_QUEUE_SERIAL);
52+ if (fsQueue == nil )
53+ fsQueue = dispatch_queue_create (" RNFetchBlob.fs.queue" , DISPATCH_QUEUE_SERIAL);
4654 BOOL isDir;
4755 // if temp folder not exists, create one
4856 if (![[NSFileManager defaultManager ] fileExistsAtPath: [RNFetchBlobFS getTempPath ] isDirectory: &isDir]) {
@@ -376,17 +384,16 @@ - (NSDictionary *)constantsToExport
376384#pragma mark - fs.readStream
377385RCT_EXPORT_METHOD (readStream:(NSString *)path withEncoding:(NSString *)encoding bufferSize:(int )bufferSize tick:(int )tick streamId:(NSString *)streamId
378386{
379-
380- // RNFetchBlobFS *fileStream = [[RNFetchBlobFS alloc] initWithBridgeRef:self.bridge];
381387 if (bufferSize == nil ) {
382388 if ([[encoding lowercaseString ] isEqualToString: @" base64" ])
383389 bufferSize = 4095 ;
384390 else
385391 bufferSize = 4096 ;
386392 }
387393
388- // [fileStream readWithPath:path useEncoding:encoding bufferSize:bufferSize];
389- [RNFetchBlobFS readStream: path encoding: encoding bufferSize: bufferSize tick: tick streamId: streamId bridgeRef: _bridge];
394+ dispatch_async (fsQueue, ^{
395+ [RNFetchBlobFS readStream: path encoding: encoding bufferSize: bufferSize tick: tick streamId: streamId bridgeRef: _bridge];
396+ });
390397})
391398
392399#pragma mark - fs.getEnvionmentDirs
0 commit comments