|
@@ -13,6 +13,7 @@
|
13
|
13
|
#import "RCTEventDispatcher.h"
|
14
|
14
|
#import "RNFetchBlobFS.h"
|
15
|
15
|
#import "RNFetchBlobConst.h"
|
|
16
|
+#import "IOS7Polyfill.h"
|
16
|
17
|
@import AssetsLibrary;
|
17
|
18
|
|
18
|
19
|
|
|
@@ -130,9 +131,10 @@ NSMutableDictionary *fileStreams = nil;
|
130
|
131
|
int read = 0;
|
131
|
132
|
int chunkSize = bufferSize;
|
132
|
133
|
// allocate buffer in heap instead of stack
|
133
|
|
- uint8_t * buffer = (uint8_t *) malloc(bufferSize);
|
|
134
|
+ uint8_t * buffer;
|
134
|
135
|
@try
|
135
|
136
|
{
|
|
137
|
+ buffer = (uint8_t *) malloc(bufferSize);
|
136
|
138
|
if(path != nil)
|
137
|
139
|
{
|
138
|
140
|
if([[NSFileManager defaultManager] fileExistsAtPath:path] == NO)
|
|
@@ -166,6 +168,9 @@ NSMutableDictionary *fileStreams = nil;
|
166
|
168
|
NSDictionary * payload = @{ @"event": FS_EVENT_ERROR, @"detail": @"RNFetchBlob.readStream unable to resolve URI" };
|
167
|
169
|
[event sendDeviceEventWithName:streamId body:payload];
|
168
|
170
|
}
|
|
171
|
+ // release buffer
|
|
172
|
+ if(buffer != nil)
|
|
173
|
+ free(buffer);
|
169
|
174
|
|
170
|
175
|
}
|
171
|
176
|
@catch (NSError * err)
|
|
@@ -175,8 +180,6 @@ NSMutableDictionary *fileStreams = nil;
|
175
|
180
|
}
|
176
|
181
|
@finally
|
177
|
182
|
{
|
178
|
|
- // release buffer
|
179
|
|
- free(buffer);
|
180
|
183
|
NSDictionary * payload = @{ @"event": FS_EVENT_END, @"detail": @"" };
|
181
|
184
|
[event sendDeviceEventWithName:streamId body:payload];
|
182
|
185
|
}
|
|
@@ -292,7 +295,7 @@ NSMutableDictionary *fileStreams = nil;
|
292
|
295
|
}
|
293
|
296
|
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
|
294
|
297
|
NSData * content = nil;
|
295
|
|
- if([encoding containsString:@"base64"]) {
|
|
298
|
+ if([encoding RNFBContainsString:@"base64"]) {
|
296
|
299
|
content = [[NSData alloc] initWithBase64EncodedString:data options:0];
|
297
|
300
|
}
|
298
|
301
|
else if([encoding isEqualToString:@"uri"]) {
|