@@ -103,7 +103,14 @@ protected Integer doInBackground(String ... args) {
103
103
}
104
104
} else if (encoding .equalsIgnoreCase ("ascii" )) {
105
105
while ((cursor = fs .read (buffer )) != -1 ) {
106
- String chunk = EncodingUtils .getAsciiString (buffer , 0 , cursor );
106
+ String chunk = "[" ;
107
+ for (int i =0 ;i <cursor ;i ++)
108
+ {
109
+ chunk += (int )buffer [i ];
110
+ if (i +1 < cursor )
111
+ chunk += "," ;
112
+ }
113
+ chunk = chunk + "]" ;
107
114
emitStreamEvent (eventName , "data" , chunk );
108
115
}
109
116
} else if (encoding .equalsIgnoreCase ("base64" )) {
@@ -127,7 +134,7 @@ protected Integer doInBackground(String ... args) {
127
134
if (!error )
128
135
emitStreamEvent (eventName , "end" , "" );
129
136
fs .close ();
130
-
137
+ buffer = null ;
131
138
132
139
} catch (Exception err ) {
133
140
emitStreamEvent (eventName , "error" , err .getLocalizedMessage ());
@@ -180,6 +187,30 @@ static void writeChunk(String streamId, String data, Callback callback) {
180
187
try {
181
188
stream .write (chunk );
182
189
callback .invoke ();
190
+ chunk = null ;
191
+ } catch (Exception e ) {
192
+ callback .invoke (e .getLocalizedMessage ());
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Write data using ascii array
198
+ * @param streamId File stream ID
199
+ * @param data Data chunk in ascii array format
200
+ * @param callback JS context callback
201
+ */
202
+ static void writeArrayChunk (String streamId , ReadableArray data , Callback callback ) {
203
+
204
+ RNFetchBlobFS fs = fileStreams .get (streamId );
205
+ OutputStream stream = fs .writeStreamInstance ;
206
+ byte [] chunk = new byte [data .size ()];
207
+ for (int i =0 ; i < data .size ();i ++) {
208
+ chunk [i ] = (byte ) data .getInt (i );
209
+ }
210
+ try {
211
+ stream .write (chunk );
212
+ callback .invoke ();
213
+ chunk = null ;
183
214
} catch (Exception e ) {
184
215
callback .invoke (e .getLocalizedMessage ());
185
216
}
@@ -343,6 +374,27 @@ static void createFile(String path, String data, String encoding, Callback callb
343
374
}
344
375
}
345
376
377
+ static void createFileASCII (String path , ReadableArray data , Callback callback ) {
378
+ try {
379
+ File dest = new File (path );
380
+ boolean created = dest .createNewFile ();
381
+ if (!created ) {
382
+ callback .invoke ("failed to create file at path `" + path + "` for its parent path may not exists" );
383
+ return ;
384
+ }
385
+ OutputStream ostream = new FileOutputStream (dest );
386
+ byte [] chunk = new byte [data .size ()];
387
+ for (int i =0 ; i <data .size ();i ++) {
388
+ chunk [i ] = (byte ) data .getInt (i );
389
+ }
390
+ ostream .write (chunk );
391
+ chunk = null ;
392
+ callback .invoke (null , path );
393
+ } catch (Exception err ) {
394
+ callback .invoke (err .getLocalizedMessage ());
395
+ }
396
+ }
397
+
346
398
static void removeSession (ReadableArray paths , Callback callback ) {
347
399
348
400
AsyncTask <ReadableArray , Integer , Integer > task = new AsyncTask <ReadableArray , Integer , Integer >() {
0 commit comments