@@ -100,7 +100,8 @@ describe('create file API test', (report, done) => {
100
100
key = "base64 content test"
101
101
expect = { raw }
102
102
actual = { d } /> )
103
- testASCII ( )
103
+ // testASCII()
104
+ done ( )
104
105
} )
105
106
} )
106
107
. catch ( ( err ) => {
@@ -225,7 +226,6 @@ describe('write stream API test', (report, done) => {
225
226
d2 += chunk
226
227
} )
227
228
rs . onEnd ( ( ) => {
228
- console . log ( RNFetchBlob . base64 . encode ( expect ) , d2 )
229
229
report (
230
230
< Assert key = "file should be overwritten by base64 encoded data"
231
231
expect = { RNFetchBlob . base64 . encode ( expect ) }
@@ -292,23 +292,76 @@ describe('cp API test', {timeout : 10000},(report, done) => {
292
292
} )
293
293
} )
294
294
295
- describe ( 'Download file to `download` folder' , ( report , done ) => {
296
- RNFetchBlob . fs
297
- . getSystemDirs ( )
295
+ describe ( 'ASCII data test' , ( report , done ) => {
296
+ let p = null
297
+ let expect = 'fetch-blob-' + Date . now ( )
298
+ fs . getSystemDirs ( )
298
299
. then ( ( dirs ) => {
299
- return RNFetchBlob . config ( {
300
- path : dirs . DownloadDir + '/download-test.png'
300
+ p = dirs . DocumentDir + '/ASCII-test-' + Date . now ( )
301
+ return fs . createFile ( p , 'utf8' )
302
+ } )
303
+ . then ( ( ) => {
304
+ return fs . writeStream ( p , 'ascii' , false )
305
+ } )
306
+ . then ( ( ofstream ) => {
307
+ let qq = [ ]
308
+ for ( let i = 0 ; i < expect . length ; i ++ ) {
309
+ qq . push ( expect [ i ] . charCodeAt ( 0 ) )
310
+ ofstream . write ( [ expect [ i ] . charCodeAt ( 0 ) ] )
311
+ }
312
+ ofstream . write ( [ 'g' . charCodeAt ( 0 ) , 'g' . charCodeAt ( 0 ) ] )
313
+ return ofstream . close ( )
314
+ } )
315
+ . then ( ( ) => {
316
+ let ifstream = fs . readStream ( p , 'ascii' )
317
+ let res = [ ]
318
+ ifstream . onData ( ( chunk ) => {
319
+ res = res . concat ( chunk )
301
320
} )
302
- . fetch ( 'GET' , `${ TEST_SERVER_URL } /public/github.png` , {
303
- Authorization : 'Bearer abde123eqweje'
321
+ ifstream . onEnd ( ( ) => {
322
+ res = res . map ( ( byte ) => {
323
+ return String . fromCharCode ( byte )
324
+ } ) . join ( '' )
325
+ report (
326
+ < Assert key = "data written in ASCII format should correct"
327
+ expect = { expect + 'gg' }
328
+ actual = { res }
329
+ /> )
330
+ done ( )
304
331
} )
305
332
} )
306
- . then ( ( resp ) => {
307
- report ( < Info key = "image in download path" >
308
- < Image
309
- style = { styles . image }
310
- source = { { uri : 'file://' + dirs . DownloadDir + '/download-test.png' } } />
311
- </ Info > )
333
+ } )
334
+
335
+ describe ( 'ASCII file test' , ( report , done ) => {
336
+ let p = ''
337
+ let filename = ''
338
+ let expect = [ ]
339
+ let base64 = RNFetchBlob . base64
340
+ fs . getSystemDirs ( ) . then ( ( dirs ) => {
341
+ p = dirs . DocumentDir + '/'
342
+ filename = 'ASCII-file-test' + Date . now ( ) + '.txt'
343
+ expect = 'ascii test ' + Date . now ( )
344
+ return fs . createFile ( p + filename , getASCIIArray ( expect ) , 'ascii' )
345
+ } )
346
+ . then ( ( ) => {
347
+ let rs = fs . readStream ( p + filename , 'base64' )
348
+ let actual = ''
349
+ rs . onData ( ( chunk ) => {
350
+ actual += chunk
351
+ } )
352
+ rs . onEnd ( ( ) => {
353
+ report ( < Assert key = "written data verify"
354
+ expect = { expect }
355
+ actual = { base64 . decode ( actual ) } /> )
312
356
done ( )
313
357
} )
358
+ } )
314
359
} )
360
+
361
+ function getASCIIArray ( str ) {
362
+ let r = [ ]
363
+ for ( let i = 0 ; i < str . length ; i ++ ) {
364
+ r . push ( str [ i ] . charCodeAt ( 0 ) )
365
+ }
366
+ return r
367
+ }
0 commit comments