@@ -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,59 @@ 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 )
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 ( )
340
+ } ) )
341
+ } , ( ) => {
342
+ expect ( files . length ) . to . equal ( 1 )
331
343
expect ( files [ 0 ] . path ) . to . equal ( hash )
332
- files [ 0 ] . content . pipe ( concat ( ( content ) => {
333
- expect ( content ) . to . deep . equal ( bigFile )
334
- done ( )
344
+ expect ( files [ 0 ] . content ) . to . deep . equal ( bigFile )
345
+ done ( )
346
+ } ) )
347
+ } )
348
+ } )
349
+
350
+ it ( 'directory' , ( done ) => {
351
+ const hash = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
352
+ ipfs . files . get ( hash , ( err , stream ) => {
353
+ expect ( err ) . to . not . exist
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 ( )
335
364
} ) )
365
+ } , ( ) => {
366
+ expect ( files ) . to . be . length ( 10 )
367
+ var paths = files . map ( ( file ) => {
368
+ return file . path
369
+ } )
370
+ expect ( paths ) . to . deep . equal ( [
371
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP' ,
372
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/alice.txt' ,
373
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/empty-folder' ,
374
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files' ,
375
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/empty' ,
376
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/hello.txt' ,
377
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/ipfs.txt' ,
378
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/holmes.txt' ,
379
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/jungle.txt' ,
380
+ 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt' ,
381
+ ] )
382
+ done ( )
336
383
} ) )
337
384
} )
338
385
} )
0 commit comments