|
@@ -229,14 +229,14 @@ class FetchBlobResponse {
|
229
|
229
|
path : () => string | null;
|
230
|
230
|
type : 'base64' | 'path' | 'utf8';
|
231
|
231
|
data : any;
|
232
|
|
- blob : (contentType:string, sliceSize:number) => null;
|
233
|
|
- text : () => string;
|
|
232
|
+ blob : (contentType:string, sliceSize:number) => Promise<Blob>;
|
|
233
|
+ text : () => string | Promise<any>;
|
234
|
234
|
json : () => any;
|
235
|
235
|
base64 : () => any;
|
236
|
236
|
flush : () => void;
|
237
|
237
|
respInfo : RNFetchBlobResponseInfo;
|
238
|
238
|
session : (name:string) => RNFetchBlobSession | null;
|
239
|
|
- readFile : (encode: 'base64' | 'utf8' | 'ascii') => ?Promise;
|
|
239
|
+ readFile : (encode: 'base64' | 'utf8' | 'ascii') => ?Promise<any>;
|
240
|
240
|
readStream : (
|
241
|
241
|
encode: 'utf8' | 'ascii' | 'base64',
|
242
|
242
|
) => RNFetchBlobStream | null;
|
|
@@ -275,18 +275,15 @@ class FetchBlobResponse {
|
275
|
275
|
* Convert result to text.
|
276
|
276
|
* @return {string} Decoded base64 string.
|
277
|
277
|
*/
|
278
|
|
- this.text = ():string => {
|
|
278
|
+ this.text = ():string | Promise<any> => {
|
279
|
279
|
let res = this.data
|
280
|
280
|
switch(this.type) {
|
281
|
281
|
case 'base64':
|
282
|
282
|
return base64.decode(this.data)
|
283
|
|
- break
|
284
|
283
|
case 'path':
|
285
|
284
|
return fs.readFile(this.data, 'base64').then((b64) => Promise.resolve(base64.decode(b64)))
|
286
|
|
- break
|
287
|
285
|
default:
|
288
|
286
|
return this.data
|
289
|
|
- break
|
290
|
287
|
}
|
291
|
288
|
}
|
292
|
289
|
/**
|
|
@@ -297,31 +294,25 @@ class FetchBlobResponse {
|
297
|
294
|
switch(this.type) {
|
298
|
295
|
case 'base64':
|
299
|
296
|
return JSON.parse(base64.decode(this.data))
|
300
|
|
- break
|
301
|
297
|
case 'path':
|
302
|
298
|
return fs.readFile(this.data, 'utf8')
|
303
|
299
|
.then((text) => Promise.resolve(JSON.parse(text)))
|
304
|
|
- break
|
305
|
300
|
default:
|
306
|
301
|
return JSON.parse(this.data)
|
307
|
|
- break
|
308
|
302
|
}
|
309
|
303
|
}
|
310
|
304
|
/**
|
311
|
305
|
* Return BASE64 string directly.
|
312
|
306
|
* @return {string} BASE64 string of response body.
|
313
|
307
|
*/
|
314
|
|
- this.base64 = ():string => {
|
|
308
|
+ this.base64 = ():string | Promise<any> => {
|
315
|
309
|
switch(this.type) {
|
316
|
310
|
case 'base64':
|
317
|
311
|
return this.data
|
318
|
|
- break
|
319
|
312
|
case 'path':
|
320
|
313
|
return fs.readFile(this.data, 'base64')
|
321
|
|
- break
|
322
|
314
|
default:
|
323
|
315
|
return base64.encode(this.data)
|
324
|
|
- break
|
325
|
316
|
}
|
326
|
317
|
}
|
327
|
318
|
/**
|
|
@@ -376,7 +367,6 @@ class FetchBlobResponse {
|
376
|
367
|
this.readFile = (encode: 'base64' | 'utf8' | 'ascii') => {
|
377
|
368
|
if(this.type === 'path') {
|
378
|
369
|
encode = encode || 'utf8'
|
379
|
|
-
|
380
|
370
|
return readFile(this.data, encode)
|
381
|
371
|
}
|
382
|
372
|
else {
|