|
@@ -41,6 +41,7 @@ NSString *const FS_EVENT_ERROR = @"error";
|
41
|
41
|
@synthesize callback;
|
42
|
42
|
@synthesize taskId;
|
43
|
43
|
@synthesize path;
|
|
44
|
+@synthesize bufferSize;
|
44
|
45
|
|
45
|
46
|
|
46
|
47
|
|
|
@@ -115,12 +116,13 @@ NSString *const FS_EVENT_ERROR = @"error";
|
115
|
116
|
}
|
116
|
117
|
}
|
117
|
118
|
|
118
|
|
-- (void)readWithPath:(NSString *)path useEncoding:(NSString *)encoding {
|
|
119
|
+- (void)readWithPath:(NSString *)path useEncoding:(NSString *)encoding bufferSize:(int) bufferSize{
|
119
|
120
|
|
120
|
121
|
self.inStream = [[NSInputStream alloc] initWithFileAtPath:path];
|
121
|
122
|
self.inStream.delegate = self;
|
122
|
123
|
self.encoding = encoding;
|
123
|
124
|
self.path = path;
|
|
125
|
+ self.bufferSize = bufferSize;
|
124
|
126
|
|
125
|
127
|
// NSStream needs a runloop so let's create a run loop for it
|
126
|
128
|
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
|
|
@@ -185,9 +187,15 @@ void runOnMainQueueWithoutDeadlocking(void (^block)(void))
|
185
|
187
|
case NSStreamEventHasBytesAvailable:
|
186
|
188
|
{
|
187
|
189
|
NSMutableData * chunkData = [[NSMutableData data] init];
|
188
|
|
- uint8_t buf[1024];
|
|
190
|
+ NSInteger chunkSize = 1024;
|
|
191
|
+ if([[self.encoding lowercaseString] isEqualToString:@"base64"])
|
|
192
|
+ chunkSize = 1026;
|
|
193
|
+ if(self.bufferSize > 0)
|
|
194
|
+ chunkSize = self.bufferSize;
|
|
195
|
+ uint8_t buf[chunkSize];
|
189
|
196
|
unsigned int len = 0;
|
190
|
|
- len = [(NSInputStream *)stream read:buf maxLength:1024];
|
|
197
|
+
|
|
198
|
+ len = [(NSInputStream *)stream read:buf maxLength:chunkSize];
|
191
|
199
|
// still have data in stream
|
192
|
200
|
if(len) {
|
193
|
201
|
[chunkData appendBytes:(const void *)buf length:len];
|
|
@@ -578,9 +586,9 @@ RCT_EXPORT_METHOD(fetchBlob:(NSDictionary *)options
|
578
|
586
|
});
|
579
|
587
|
}
|
580
|
588
|
|
581
|
|
-RCT_EXPORT_METHOD(readStream:(NSString *)path withEncoding:(NSString *)encoding) {
|
|
589
|
+RCT_EXPORT_METHOD(readStream:(NSString *)path withEncoding:(NSString *)encoding bufferSize:(int)bufferSize) {
|
582
|
590
|
FetchBlobFS *fileStream = [[FetchBlobFS alloc] initWithBridgeRef:self.bridge];
|
583
|
|
- [fileStream readWithPath:path useEncoding:encoding];
|
|
591
|
+ [fileStream readWithPath:path useEncoding:encoding bufferSize:bufferSize];
|
584
|
592
|
}
|
585
|
593
|
|
586
|
594
|
RCT_EXPORT_METHOD(flush:(NSString *)path) {
|