@@ -299,14 +299,21 @@ module.exports = (common) => {
299
299
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
300
300
ipfs . files . get ( hash , ( err , stream ) => {
301
301
expect ( err ) . to . not . exist
302
- stream . pipe ( concat ( ( files ) => {
303
- expect ( err ) . to . not . exist
304
- expect ( files ) . to . be . length ( 1 )
305
- expect ( files [ 0 ] . path ) . to . equal ( hash )
306
- files [ 0 ] . content . pipe ( concat ( ( content ) => {
307
- expect ( content . toString ( ) ) . to . contain ( 'Plz add me!' )
308
- done ( )
302
+
303
+ let files = [ ]
304
+ stream . pipe ( through . obj ( ( file , enc , next ) => {
305
+ file . content . pipe ( concat ( ( content ) => {
306
+ files . push ( {
307
+ path : file . path ,
308
+ content : content
309
+ } )
310
+ next ( )
309
311
} ) )
312
+ } , ( ) => {
313
+ expect ( files ) . to . be . length ( 1 )
314
+ expect ( files [ 0 ] . path ) . to . be . eql ( hash )
315
+ expect ( files [ 0 ] . content . toString ( ) ) . to . contain ( 'Plz add me!' )
316
+ done ( )
310
317
} ) )
311
318
} )
312
319
} )
@@ -316,13 +323,21 @@ module.exports = (common) => {
316
323
const mhBuf = new Buffer ( bs58 . decode ( hash ) )
317
324
ipfs . files . get ( mhBuf , ( err , stream ) => {
318
325
expect ( err ) . to . not . exist
319
- stream . pipe ( concat ( ( files ) => {
320
- expect ( files ) . to . be . length ( 1 )
321
- expect ( files [ 0 ] . path ) . to . deep . equal ( hash )
322
- files [ 0 ] . content . pipe ( concat ( ( content ) => {
323
- expect ( content . toString ( ) ) . to . contain ( 'Plz add me!' )
324
- done ( )
326
+
327
+ let files = [ ]
328
+ stream . pipe ( through . obj ( ( file , enc , next ) => {
329
+ file . content . pipe ( concat ( ( content ) => {
330
+ files . push ( {
331
+ path : file . path ,
332
+ content : content
333
+ } )
334
+ next ( )
325
335
} ) )
336
+ } , ( ) => {
337
+ expect ( files ) . to . be . length ( 1 )
338
+ expect ( files [ 0 ] . path ) . to . be . eql ( hash )
339
+ expect ( files [ 0 ] . content . toString ( ) ) . to . contain ( 'Plz add me!' )
340
+ done ( )
326
341
} ) )
327
342
} )
328
343
} )
@@ -412,37 +427,41 @@ module.exports = (common) => {
412
427
} )
413
428
414
429
describe ( 'promise' , ( ) => {
415
- it ( 'with a base58 encoded string' , ( done ) => {
430
+ it ( 'with a base58 encoded string' , ( ) => {
416
431
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
417
- ipfs . files . get ( hash )
418
- . then ( ( stream ) => {
419
- stream . pipe ( concat ( ( files ) => {
432
+ return ipfs . files . get ( hash ) . then ( ( stream ) => {
433
+ let files = [ ]
434
+ return new Promise ( ( resolve , reject ) => {
435
+ stream . pipe ( through . obj ( ( file , enc , next ) => {
436
+ file . content . pipe ( concat ( ( content ) => {
437
+ files . push ( {
438
+ path : file . path ,
439
+ content : content
440
+ } )
441
+ next ( )
442
+ } ) )
443
+ } , ( ) => {
420
444
expect ( files ) . to . be . length ( 1 )
421
445
expect ( files [ 0 ] . path ) . to . equal ( hash )
422
- files [ 0 ] . content . pipe ( concat ( ( content ) => {
423
- expect ( content . toString ( ) ) . to . contain ( 'Plz add me!' )
424
- done ( )
425
- } ) )
446
+ expect ( files [ 0 ] . content . toString ( ) ) . to . contain ( 'Plz add me!' )
447
+ resolve ( )
426
448
} ) )
427
449
} )
428
- . catch ( ( err ) => {
429
- expect ( err ) . to . not . exist
430
- } )
450
+ } )
431
451
} )
432
452
433
453
it ( 'errors on invalid key' , ( ) => {
434
454
const hash = 'somethingNotMultihash'
435
- return ipfs . files . get ( hash )
436
- . catch ( ( err ) => {
437
- expect ( err ) . to . exist
438
- const errString = err . toString ( )
439
- if ( errString === 'Error: invalid ipfs ref path' ) {
440
- expect ( err . toString ( ) ) . to . contain ( 'Error: invalid ipfs ref path' )
441
- }
442
- if ( errString === 'Error: Invalid Key' ) {
443
- expect ( err . toString ( ) ) . to . contain ( 'Error: Invalid Key' )
444
- }
445
- } )
455
+ return ipfs . files . get ( hash ) . catch ( ( err ) => {
456
+ expect ( err ) . to . exist
457
+ const errString = err . toString ( )
458
+ if ( errString === 'Error: invalid ipfs ref path' ) {
459
+ expect ( err . toString ( ) ) . to . contain ( 'Error: invalid ipfs ref path' )
460
+ }
461
+ if ( errString === 'Error: Invalid Key' ) {
462
+ expect ( err . toString ( ) ) . to . contain ( 'Error: Invalid Key' )
463
+ }
464
+ } )
446
465
} )
447
466
} )
448
467
} )
0 commit comments