@@ -7,10 +7,10 @@ const Readable = require('readable-stream')
7
7
const path = require ( 'path' )
8
8
const fs = require ( 'fs' )
9
9
const isNode = require ( 'detect-node' )
10
- const bl = require ( 'bl ' )
10
+ const concat = require ( 'concat-stream ' )
11
11
12
12
module . exports = ( common ) => {
13
- describe ( '.files' , ( ) => {
13
+ describe . only ( '.files' , ( ) => {
14
14
let smallFile
15
15
let bigFile
16
16
let ipfs
@@ -209,8 +209,7 @@ module.exports = (common) => {
209
209
const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
210
210
ipfs . cat ( hash , ( err , stream ) => {
211
211
expect ( err ) . to . not . exist
212
- stream . pipe ( bl ( ( err , data ) => {
213
- expect ( err ) . to . not . exist
212
+ stream . pipe ( concat ( ( data ) => {
214
213
expect ( data . toString ( ) ) . to . contain ( 'Check out some of the other files in this directory:' )
215
214
done ( )
216
215
} ) )
@@ -221,8 +220,7 @@ module.exports = (common) => {
221
220
const mhBuf = new Buffer ( bs58 . decode ( 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB' ) )
222
221
ipfs . cat ( mhBuf , ( err , stream ) => {
223
222
expect ( err ) . to . not . exist
224
- stream . pipe ( bl ( ( err , data ) => {
225
- expect ( err ) . to . not . exist
223
+ stream . pipe ( concat ( ( data ) => {
226
224
expect ( data . toString ( ) ) . to . contain ( 'Check out some of the other files in this directory:' )
227
225
done ( )
228
226
} ) )
@@ -233,8 +231,7 @@ module.exports = (common) => {
233
231
const hash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
234
232
ipfs . cat ( hash , ( err , stream ) => {
235
233
expect ( err ) . to . not . exist
236
- stream . pipe ( bl ( ( err , data ) => {
237
- expect ( err ) . to . not . exist
234
+ stream . pipe ( concat ( ( data ) => {
238
235
expect ( data ) . to . deep . equal ( bigFile )
239
236
done ( )
240
237
} ) )
@@ -246,8 +243,7 @@ module.exports = (common) => {
246
243
const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
247
244
ipfs . cat ( hash )
248
245
. then ( ( stream ) => {
249
- stream . pipe ( bl ( ( err , data ) => {
250
- expect ( err ) . to . not . exist
246
+ stream . pipe ( concat ( ( data ) => {
251
247
expect ( data . toString ( ) ) . to . contain ( 'Check out some of the other files in this directory:' )
252
248
done ( )
253
249
} ) )
@@ -278,8 +274,7 @@ module.exports = (common) => {
278
274
const hash = new Buffer ( bs58 . decode ( 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB' ) )
279
275
ipfs . cat ( hash )
280
276
. then ( ( stream ) => {
281
- stream . pipe ( bl ( ( err , bldata ) => {
282
- expect ( err ) . to . not . exist
277
+ stream . pipe ( concat ( ( bldata ) => {
283
278
expect ( bldata . toString ( ) ) . to . contain ( 'Check out some of the other files in this directory:' )
284
279
done ( )
285
280
} ) )
@@ -290,5 +285,91 @@ module.exports = (common) => {
290
285
} )
291
286
} )
292
287
} )
288
+
289
+ describe ( '.get' , ( ) => {
290
+ it ( 'with a base58 encoded multihash' , ( done ) => {
291
+ const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
292
+ ipfs . files . get ( hash , ( err , stream ) => {
293
+ expect ( err ) . to . not . exist
294
+ stream . pipe ( concat ( ( files ) => {
295
+ expect ( err ) . to . not . exist
296
+ expect ( files ) . to . be . length ( 1 )
297
+ expect ( files [ 0 ] . path ) . to . equal ( hash )
298
+ files [ 0 ] . content . pipe ( concat ( ( content ) => {
299
+ expect ( content . toString ( ) ) . to . contain ( 'Check out some of the other files in this directory:' )
300
+ done ( )
301
+ } ) )
302
+ } ) )
303
+ } )
304
+ } )
305
+
306
+ it ( 'with a multihash' , ( done ) => {
307
+ const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
308
+ const mhBuf = new Buffer ( bs58 . decode ( hash ) )
309
+ ipfs . files . get ( mhBuf , ( err , stream ) => {
310
+ expect ( err ) . to . not . exist
311
+ stream . pipe ( concat ( ( files ) => {
312
+ expect ( files ) . to . be . length ( 1 )
313
+ expect ( files [ 0 ] . path ) . to . deep . equal ( mhBuf )
314
+ files [ 0 ] . content . pipe ( concat ( ( content ) => {
315
+ expect ( content . toString ( ) ) . to . contain ( 'Check out some of the other files in this directory:' )
316
+ done ( )
317
+ } ) )
318
+ } ) )
319
+ } )
320
+ } )
321
+
322
+ it ( 'large file' , ( done ) => {
323
+ const hash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
324
+ ipfs . files . get ( hash , ( err , stream ) => {
325
+ expect ( err ) . to . not . exist
326
+ stream . pipe ( concat ( ( files ) => {
327
+ expect ( files ) . to . be . length ( 1 )
328
+ expect ( files [ 0 ] . path ) . to . equal ( hash )
329
+ files [ 0 ] . content . pipe ( concat ( ( content ) => {
330
+ expect ( content ) . to . deep . equal ( bigFile )
331
+ done ( )
332
+ } ) )
333
+ } ) )
334
+ } )
335
+ } )
336
+
337
+ describe ( 'promise' , ( ) => {
338
+ it ( 'with a base58 encoded string' , ( done ) => {
339
+ const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
340
+ ipfs . files . get ( hash )
341
+ . then ( ( stream ) => {
342
+ stream . pipe ( concat ( ( files ) => {
343
+ expect ( files ) . to . be . length ( 1 )
344
+ expect ( files [ 0 ] . path ) . to . equal ( hash )
345
+ files [ 0 ] . content . pipe ( concat ( ( content ) => {
346
+ expect ( content . toString ( ) ) . to . contain ( 'Check out some of the other files in this directory:' )
347
+ done ( )
348
+ } ) )
349
+ } ) )
350
+ } )
351
+ . catch ( ( err ) => {
352
+ expect ( err ) . to . not . exist
353
+ } )
354
+ } )
355
+
356
+ it ( 'errors on invalid key' , ( done ) => {
357
+ const hash = 'somethingNotMultihash'
358
+ ipfs . files . get ( hash )
359
+ . then ( ( stream ) => { } )
360
+ . catch ( ( err ) => {
361
+ expect ( err ) . to . exist
362
+ const errString = err . toString ( )
363
+ if ( errString === 'Error: invalid ipfs ref path' ) {
364
+ expect ( err . toString ( ) ) . to . contain ( 'Error: invalid ipfs ref path' )
365
+ }
366
+ if ( errString === 'Error: Invalid Key' ) {
367
+ expect ( err . toString ( ) ) . to . contain ( 'Error: Invalid Key' )
368
+ }
369
+ done ( )
370
+ } )
371
+ } )
372
+ } )
373
+ } )
293
374
} )
294
375
}
0 commit comments