Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 02874f0

Browse files
committed
Correct IOS readStream exception handling
1 parent 3ab1732 commit 02874f0

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/ios/RNFetchBlobFS.m

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ @implementation RNFetchBlobFS
3636
@synthesize appendData;
3737
@synthesize bufferSize;
3838

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+
3956
// static member getter
4057
+ (NSArray *) getFileStreams {
4158

@@ -118,6 +135,13 @@ + (void) readStream:(NSString *)uri
118135

119136
if(path != nil)
120137
{
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+
}
121145
NSInputStream * stream = [[NSInputStream alloc] initWithFileAtPath:path];
122146
[stream open];
123147
while((read = [stream read:buffer maxLength:bufferSize]) > 0)
@@ -144,7 +168,6 @@ + (void) readStream:(NSString *)uri
144168
}
145169
@catch (NSError * err)
146170
{
147-
148171
NSDictionary * payload = @{ @"event": FS_EVENT_ERROR, @"detail": [NSString stringWithFormat:@"RNFetchBlob.readStream error %@", [err description]] };
149172
[event sendDeviceEventWithName:streamId body:payload];
150173
}
@@ -471,23 +494,6 @@ + (void) exists:(NSString *) path callback:(RCTResponseSenderBlock)callback
471494
}];
472495
}
473496

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-
491497
# pragma mark - open file stream
492498

493499
// Create file stream for write data

0 commit comments

Comments
 (0)