Browse Source

Correct IOS readStream exception handling

Ben Hsieh 8 years ago
parent
commit
02874f06bc
1 changed files with 24 additions and 18 deletions
  1. 24
    18
      src/ios/RNFetchBlobFS.m

+ 24
- 18
src/ios/RNFetchBlobFS.m View File

36
 @synthesize appendData;
36
 @synthesize appendData;
37
 @synthesize bufferSize;
37
 @synthesize bufferSize;
38
 
38
 
39
+- (id)init {
40
+    self = [super init];
41
+    return self;
42
+}
43
+
44
+- (id)initWithCallback:(RCTResponseSenderBlock)callback {
45
+    self = [super init];
46
+    self.callback = callback;
47
+    return self;
48
+}
49
+
50
+- (id)initWithBridgeRef:(RCTBridge *)bridgeRef {
51
+    self = [super init];
52
+    self.bridge = bridgeRef;
53
+    return self;
54
+}
55
+
39
 // static member getter
56
 // static member getter
40
 + (NSArray *) getFileStreams {
57
 + (NSArray *) getFileStreams {
41
     
58
     
118
             
135
             
119
             if(path != nil)
136
             if(path != nil)
120
             {
137
             {
138
+                if([[NSFileManager defaultManager] fileExistsAtPath:path] == NO)
139
+                {
140
+                    NSString * message = [NSString stringWithFormat:@"File not exists at path %@", path];
141
+                    NSDictionary * payload = @{ @"event": FS_EVENT_ERROR, @"detail": message };
142
+                    [event sendDeviceEventWithName:streamId body:payload];
143
+                    return ;
144
+                }
121
                 NSInputStream * stream = [[NSInputStream alloc] initWithFileAtPath:path];
145
                 NSInputStream * stream = [[NSInputStream alloc] initWithFileAtPath:path];
122
                 [stream open];
146
                 [stream open];
123
                 while((read = [stream read:buffer maxLength:bufferSize]) > 0)
147
                 while((read = [stream read:buffer maxLength:bufferSize]) > 0)
144
         }
168
         }
145
         @catch (NSError * err)
169
         @catch (NSError * err)
146
         {
170
         {
147
-            
148
             NSDictionary * payload = @{ @"event": FS_EVENT_ERROR, @"detail": [NSString stringWithFormat:@"RNFetchBlob.readStream error %@", [err description]] };
171
             NSDictionary * payload = @{ @"event": FS_EVENT_ERROR, @"detail": [NSString stringWithFormat:@"RNFetchBlob.readStream error %@", [err description]] };
149
             [event sendDeviceEventWithName:streamId body:payload];
172
             [event sendDeviceEventWithName:streamId body:payload];
150
         }
173
         }
471
     }];
494
     }];
472
 }
495
 }
473
 
496
 
474
-- (id)init {
475
-    self = [super init];
476
-    return self;
477
-}
478
-
479
-- (id)initWithCallback:(RCTResponseSenderBlock)callback {
480
-    self = [super init];
481
-    self.callback = callback;
482
-    return self;
483
-}
484
-
485
-- (id)initWithBridgeRef:(RCTBridge *)bridgeRef {
486
-    self = [super init];
487
-    self.bridge = bridgeRef;
488
-    return self;
489
-}
490
-
491
 # pragma mark - open file stream
497
 # pragma mark - open file stream
492
 
498
 
493
 // Create file stream for write data
499
 // Create file stream for write data