@@ -8,9 +8,10 @@ const path = require('path')
8
8
const fs = require ( 'fs' )
9
9
const isNode = require ( 'detect-node' )
10
10
const concat = require ( 'concat-stream' )
11
+ const through = require ( 'through2' )
11
12
12
13
module . exports = ( common ) => {
13
- describe . only ( '.files' , ( ) => {
14
+ describe ( '.files' , ( ) => {
14
15
let smallFile
15
16
let bigFile
16
17
let ipfs
@@ -313,7 +314,7 @@ module.exports = (common) => {
313
314
expect ( err ) . to . not . exist
314
315
stream . pipe ( concat ( ( files ) => {
315
316
expect ( files ) . to . be . length ( 1 )
316
- expect ( files [ 0 ] . path ) . to . deep . equal ( mhBuf )
317
+ expect ( files [ 0 ] . path ) . to . deep . equal ( hash )
317
318
files [ 0 ] . content . pipe ( concat ( ( content ) => {
318
319
expect ( content . toString ( ) ) . to . contain ( 'Check out some of the other files in this directory:' )
319
320
done ( )
@@ -326,13 +327,22 @@ module.exports = (common) => {
326
327
const hash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
327
328
ipfs . files . get ( hash , ( err , stream ) => {
328
329
expect ( err ) . to . not . exist
329
- stream . pipe ( concat ( ( files ) => {
330
- expect ( files ) . to . be . length ( 1 )
331
- expect ( files [ 0 ] . path ) . to . equal ( hash )
332
- files [ 0 ] . content . pipe ( concat ( ( content ) => {
333
- expect ( content ) . to . deep . equal ( bigFile )
334
- done ( )
330
+
331
+ // accumulate the files and their content
332
+ var files = [ ]
333
+ stream . pipe ( through . obj ( ( file , enc , next ) => {
334
+ file . content . pipe ( concat ( ( content ) => {
335
+ files . push ( {
336
+ path : file . path ,
337
+ content : content
338
+ } )
339
+ next ( )
335
340
} ) )
341
+ } , ( ) => {
342
+ expect ( files . length ) . to . equal ( 1 )
343
+ expect ( files [ 0 ] . path ) . to . equal ( hash )
344
+ expect ( files [ 0 ] . content ) . to . deep . equal ( bigFile )
345
+ done ( )
336
346
} ) )
337
347
} )
338
348
} )
@@ -341,21 +351,35 @@ module.exports = (common) => {
341
351
const hash = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
342
352
ipfs . files . get ( hash , ( err , stream ) => {
343
353
expect ( err ) . to . not . exist
344
- stream . pipe ( concat ( ( files ) => {
345
- expect ( files ) . to . be . length ( 8 )
354
+
355
+ // accumulate the files and their content
356
+ var files = [ ]
357
+ stream . pipe ( through . obj ( ( file , enc , next ) => {
358
+ file . content . pipe ( concat ( ( content ) => {
359
+ files . push ( {
360
+ path : file . path ,
361
+ content : content
362
+ } )
363
+ next ( )
364
+ } ) )
365
+ } , ( ) => {
366
+ expect ( files ) . to . be . length ( 10 )
346
367
var paths = files . map ( ( file ) => {
347
368
return file . path
348
369
} )
349
370
expect ( paths ) . to . deep . equal ( [
371
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP' ,
350
372
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/alice.txt' ,
351
373
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/empty-folder' ,
374
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files' ,
375
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/empty' ,
376
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/hello.txt' ,
377
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/ipfs.txt' ,
352
378
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/holmes.txt' ,
353
379
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/jungle.txt' ,
354
380
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt' ,
355
- 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/empty' ,
356
- 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/hello.txt' ,
357
- 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/ipfs.txt'
358
381
] )
382
+ done ( )
359
383
} ) )
360
384
} )
361
385
} )
0 commit comments