@@ -299,14 +299,21 @@ module.exports = (common) => {
299299 const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
300300 ipfs . files . get ( hash , ( err , stream ) => {
301301 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 ( )
309311 } ) )
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 ( )
310317 } ) )
311318 } )
312319 } )
@@ -316,13 +323,21 @@ module.exports = (common) => {
316323 const mhBuf = new Buffer ( bs58 . decode ( hash ) )
317324 ipfs . files . get ( mhBuf , ( err , stream ) => {
318325 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 ( )
325335 } ) )
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 ( )
326341 } ) )
327342 } )
328343 } )
@@ -412,37 +427,41 @@ module.exports = (common) => {
412427 } )
413428
414429 describe ( 'promise' , ( ) => {
415- it ( 'with a base58 encoded string' , ( done ) => {
430+ it ( 'with a base58 encoded string' , ( ) => {
416431 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+ } , ( ) => {
420444 expect ( files ) . to . be . length ( 1 )
421445 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 ( )
426448 } ) )
427449 } )
428- . catch ( ( err ) => {
429- expect ( err ) . to . not . exist
430- } )
450+ } )
431451 } )
432452
433453 it ( 'errors on invalid key' , ( ) => {
434454 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+ } )
446465 } )
447466 } )
448467 } )
0 commit comments