|
|
@@ -77,51 +77,34 @@ describe('create file API test', (report, done) => {
|
|
77
|
77
|
|
|
78
|
78
|
fs.createFile(p, raw, 'utf8')
|
|
79
|
79
|
.then(() => {
|
|
80
|
|
- let stream = fs.readStream(p, 'utf8')
|
|
81
|
80
|
let d = ''
|
|
82
|
|
- stream.onData((chunk) => {
|
|
83
|
|
- d += chunk
|
|
84
|
|
- })
|
|
85
|
|
- stream.onEnd(() => {
|
|
86
|
|
- report(<Assert key="utf8 content test" expect={raw} actual={d}/>)
|
|
87
|
|
- testBase64()
|
|
88
|
|
- })
|
|
89
|
|
- })
|
|
90
|
|
- function testBase64() {
|
|
91
|
|
- fs.createFile(p + '-base64', RNFetchBlob.base64.encode(raw), 'base64')
|
|
92
|
|
- .then(() => {
|
|
93
|
|
- let stream = fs.readStream(p + '-base64', 'utf8')
|
|
94
|
|
- let d = ''
|
|
|
81
|
+ fs.readStream(p, 'utf8').then((stream) => {
|
|
|
82
|
+ stream.open()
|
|
95
|
83
|
stream.onData((chunk) => {
|
|
96
|
84
|
d += chunk
|
|
97
|
85
|
})
|
|
98
|
86
|
stream.onEnd(() => {
|
|
99
|
|
- report(<Assert
|
|
100
|
|
- key="base64 content test"
|
|
101
|
|
- expect={raw}
|
|
102
|
|
- actual={d}/>)
|
|
103
|
|
- // testASCII()
|
|
104
|
|
- done()
|
|
|
87
|
+ report(<Assert key="utf8 content test" expect={raw} actual={d}/>)
|
|
|
88
|
+ testBase64()
|
|
105
|
89
|
})
|
|
106
|
90
|
})
|
|
107
|
|
- .catch((err) => {
|
|
108
|
|
- console.log(err)
|
|
109
|
|
- })
|
|
110
|
|
- }
|
|
111
|
|
- function testASCII() {
|
|
112
|
|
- fs.createFile(p + '-ascii', raw, 'ascii')
|
|
|
91
|
+ })
|
|
|
92
|
+ function testBase64() {
|
|
|
93
|
+ fs.createFile(p + '-base64', RNFetchBlob.base64.encode(raw), 'base64')
|
|
113
|
94
|
.then(() => {
|
|
114
|
|
- let stream = fs.readStream(p + '-ascii', 'ascii')
|
|
115
|
|
- let d = ''
|
|
116
|
|
- stream.onData((chunk) => {
|
|
117
|
|
- d += chunk
|
|
118
|
|
- })
|
|
119
|
|
- stream.onEnd(() => {
|
|
120
|
|
- report(<Assert
|
|
121
|
|
- key="ASCII content test"
|
|
122
|
|
- expect={raw}
|
|
123
|
|
- actual={d}/>)
|
|
124
|
|
- done()
|
|
|
95
|
+ fs.readStream(p + '-base64', 'utf8').then((stream) => {
|
|
|
96
|
+ stream.open()
|
|
|
97
|
+ let d = ''
|
|
|
98
|
+ stream.onData((chunk) => {
|
|
|
99
|
+ d += chunk
|
|
|
100
|
+ })
|
|
|
101
|
+ stream.onEnd(() => {
|
|
|
102
|
+ report(<Assert
|
|
|
103
|
+ key="base64 content test"
|
|
|
104
|
+ expect={raw}
|
|
|
105
|
+ actual={d}/>)
|
|
|
106
|
+ done()
|
|
|
107
|
+ })
|
|
125
|
108
|
})
|
|
126
|
109
|
})
|
|
127
|
110
|
.catch((err) => {
|
|
|
@@ -197,17 +180,19 @@ describe('write stream API test', (report, done) => {
|
|
197
|
180
|
return ws.close()
|
|
198
|
181
|
})
|
|
199
|
182
|
.then(() => {
|
|
200
|
|
- let rs = fs.readStream(p, 'utf8')
|
|
201
|
183
|
let d1 = ''
|
|
202
|
|
- rs.onData((chunk) => {
|
|
203
|
|
- d1 += chunk
|
|
204
|
|
- })
|
|
205
|
|
- rs.onEnd(() => {
|
|
206
|
|
- report(
|
|
207
|
|
- <Assert key="write data async test"
|
|
208
|
|
- expect={'123456789011121314'}
|
|
209
|
|
- actual={d1}/>)
|
|
210
|
|
- base64Test()
|
|
|
184
|
+ fs.readStream(p, 'utf8').then((stream) => {
|
|
|
185
|
+ stream.open()
|
|
|
186
|
+ stream.onData((chunk) => {
|
|
|
187
|
+ d1 += chunk
|
|
|
188
|
+ })
|
|
|
189
|
+ stream.onEnd(() => {
|
|
|
190
|
+ report(
|
|
|
191
|
+ <Assert key="write data async test"
|
|
|
192
|
+ expect={'123456789011121314'}
|
|
|
193
|
+ actual={d1}/>)
|
|
|
194
|
+ base64Test()
|
|
|
195
|
+ })
|
|
211
|
196
|
})
|
|
212
|
197
|
})
|
|
213
|
198
|
function base64Test() {
|
|
|
@@ -220,12 +205,15 @@ describe('write stream API test', (report, done) => {
|
|
220
|
205
|
return ws.close()
|
|
221
|
206
|
})
|
|
222
|
207
|
.then(() => {
|
|
223
|
|
- let rs = fs.readStream(p, 'base64')
|
|
|
208
|
+ return fs.readStream(p, 'base64')
|
|
|
209
|
+ })
|
|
|
210
|
+ .then((stream) => {
|
|
224
|
211
|
let d2 = ''
|
|
225
|
|
- rs.onData((chunk) => {
|
|
|
212
|
+ stream.open()
|
|
|
213
|
+ stream.onData((chunk) => {
|
|
226
|
214
|
d2 += chunk
|
|
227
|
215
|
})
|
|
228
|
|
- rs.onEnd(() => {
|
|
|
216
|
+ stream.onEnd(() => {
|
|
229
|
217
|
report(
|
|
230
|
218
|
<Assert key="file should be overwritten by base64 encoded data"
|
|
231
|
219
|
expect={RNFetchBlob.base64.encode(expect)}
|
|
|
@@ -254,14 +242,16 @@ describe('mv API test', {timeout : 10000},(report, done) => {
|
|
254
|
242
|
})
|
|
255
|
243
|
.then((files) => {
|
|
256
|
244
|
report(<Assert key="file name should be correct" expect={'moved'} actual={files[0]}/>)
|
|
257
|
|
- let rs = fs.readStream(dest + '/moved')
|
|
258
|
|
- let actual = ''
|
|
259
|
|
- rs.onData((chunk) => {
|
|
260
|
|
- actual += chunk
|
|
261
|
|
- })
|
|
262
|
|
- rs.onEnd(() => {
|
|
263
|
|
- report(<Assert key="file content should be correct" expect={content} actual={actual}/>)
|
|
264
|
|
- done()
|
|
|
245
|
+ fs.readStream(dest + '/moved').then((rs) => {
|
|
|
246
|
+ rs.open()
|
|
|
247
|
+ let actual = ''
|
|
|
248
|
+ rs.onData((chunk) => {
|
|
|
249
|
+ actual += chunk
|
|
|
250
|
+ })
|
|
|
251
|
+ rs.onEnd(() => {
|
|
|
252
|
+ report(<Assert key="file content should be correct" expect={content} actual={actual}/>)
|
|
|
253
|
+ done()
|
|
|
254
|
+ })
|
|
265
|
255
|
})
|
|
266
|
256
|
})
|
|
267
|
257
|
})
|
|
|
@@ -280,14 +270,16 @@ describe('cp API test', {timeout : 10000},(report, done) => {
|
|
280
|
270
|
})
|
|
281
|
271
|
.then((files) => {
|
|
282
|
272
|
report(<Assert key="file name should be correct" expect={'cp'} actual={files[0]}/>)
|
|
283
|
|
- let rs = fs.readStream(dest + '/cp')
|
|
284
|
|
- let actual = ''
|
|
285
|
|
- rs.onData((chunk) => {
|
|
286
|
|
- actual += chunk
|
|
287
|
|
- })
|
|
288
|
|
- rs.onEnd(() => {
|
|
289
|
|
- report(<Assert key="file content should be correct" expect={content} actual={actual}/>)
|
|
290
|
|
- done()
|
|
|
273
|
+ fs.readStream(dest + '/cp').then((rs) => {
|
|
|
274
|
+ rs.open()
|
|
|
275
|
+ let actual = ''
|
|
|
276
|
+ rs.onData((chunk) => {
|
|
|
277
|
+ actual += chunk
|
|
|
278
|
+ })
|
|
|
279
|
+ rs.onEnd(() => {
|
|
|
280
|
+ report(<Assert key="file content should be correct" expect={content} actual={actual}/>)
|
|
|
281
|
+ done()
|
|
|
282
|
+ })
|
|
291
|
283
|
})
|
|
292
|
284
|
})
|
|
293
|
285
|
})
|
|
|
@@ -304,30 +296,30 @@ describe('ASCII data test', (report, done) => {
|
|
304
|
296
|
return fs.writeStream(p, 'ascii', false)
|
|
305
|
297
|
})
|
|
306
|
298
|
.then((ofstream) => {
|
|
307
|
|
- let qq = []
|
|
308
|
299
|
for(let i=0;i<expect.length;i++) {
|
|
309
|
|
- qq.push(expect[i].charCodeAt(0))
|
|
310
|
300
|
ofstream.write([expect[i].charCodeAt(0)])
|
|
311
|
301
|
}
|
|
312
|
302
|
ofstream.write(['g'.charCodeAt(0), 'g'.charCodeAt(0)])
|
|
313
|
303
|
return ofstream.close()
|
|
314
|
304
|
})
|
|
315
|
305
|
.then(() => {
|
|
316
|
|
- let ifstream = fs.readStream(p, 'ascii')
|
|
317
|
|
- let res = []
|
|
318
|
|
- ifstream.onData((chunk) => {
|
|
319
|
|
- res = res.concat(chunk)
|
|
320
|
|
- })
|
|
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()
|
|
|
306
|
+ fs.readStream(p, 'ascii').then((ifstream) => {
|
|
|
307
|
+ let res = []
|
|
|
308
|
+ ifstream.open()
|
|
|
309
|
+ ifstream.onData((chunk) => {
|
|
|
310
|
+ res = res.concat(chunk)
|
|
|
311
|
+ })
|
|
|
312
|
+ ifstream.onEnd(() => {
|
|
|
313
|
+ res = res.map((byte) => {
|
|
|
314
|
+ return String.fromCharCode(byte)
|
|
|
315
|
+ }).join('')
|
|
|
316
|
+ report(
|
|
|
317
|
+ <Assert key="data written in ASCII format should correct"
|
|
|
318
|
+ expect={expect + 'gg'}
|
|
|
319
|
+ actual={res}
|
|
|
320
|
+ />)
|
|
|
321
|
+ done()
|
|
|
322
|
+ })
|
|
331
|
323
|
})
|
|
332
|
324
|
})
|
|
333
|
325
|
})
|
|
|
@@ -344,16 +336,42 @@ describe('ASCII file test', (report, done) => {
|
|
344
|
336
|
return fs.createFile(p + filename, getASCIIArray(expect), 'ascii')
|
|
345
|
337
|
})
|
|
346
|
338
|
.then(() => {
|
|
347
|
|
- let rs = fs.readStream(p + filename, 'base64')
|
|
348
|
|
- let actual = ''
|
|
349
|
|
- rs.onData((chunk) => {
|
|
350
|
|
- actual += chunk
|
|
|
339
|
+ fs.readStream(p + filename, 'base64').then((rs) => {
|
|
|
340
|
+ let actual = ''
|
|
|
341
|
+ rs.open()
|
|
|
342
|
+ rs.onData((chunk) => {
|
|
|
343
|
+ actual += chunk
|
|
|
344
|
+ })
|
|
|
345
|
+ rs.onEnd(() => {
|
|
|
346
|
+ report(<Assert key="written data verify"
|
|
|
347
|
+ expect={expect}
|
|
|
348
|
+ actual={base64.decode(actual)}/>)
|
|
|
349
|
+ done()
|
|
|
350
|
+ })
|
|
351
|
351
|
})
|
|
352
|
|
- rs.onEnd(() => {
|
|
353
|
|
- report(<Assert key="written data verify"
|
|
354
|
|
- expect={expect}
|
|
355
|
|
- actual={base64.decode(actual)}/>)
|
|
356
|
|
- done()
|
|
|
352
|
+ })
|
|
|
353
|
+})
|
|
|
354
|
+
|
|
|
355
|
+describe('format conversion', (report, done) => {
|
|
|
356
|
+ let p = ''
|
|
|
357
|
+ fs.getSystemDirs().then((dirs) => {
|
|
|
358
|
+ p = dirs.DocumentDir + '/foo'
|
|
|
359
|
+ return fs.createFile(p, [102, 111, 111], 'ascii')
|
|
|
360
|
+ })
|
|
|
361
|
+ .then(() => {
|
|
|
362
|
+ fs.readStream(p, 'utf8').then((stream) => {
|
|
|
363
|
+ let res = []
|
|
|
364
|
+ stream.open()
|
|
|
365
|
+ stream.onData((chunk) => {
|
|
|
366
|
+ res+=chunk
|
|
|
367
|
+ })
|
|
|
368
|
+ stream.onEnd(() => {
|
|
|
369
|
+ report(
|
|
|
370
|
+ <Assert key="write utf8 and read by ascii"
|
|
|
371
|
+ expect="foo"
|
|
|
372
|
+ actual={res}/>)
|
|
|
373
|
+ done()
|
|
|
374
|
+ })
|
|
357
|
375
|
})
|
|
358
|
376
|
})
|
|
359
|
377
|
})
|