@@ -9,6 +9,8 @@ const chai = require('chai')
9
9
const dirtyChai = require ( 'dirty-chai' )
10
10
const expect = chai . expect
11
11
chai . use ( dirtyChai )
12
+ const pull = require ( 'pull-stream' )
13
+ const CID = require ( 'cids' )
12
14
13
15
const MockPreloadNode = require ( '../utils/mock-preload-node' )
14
16
const IPFS = require ( '../../src' )
@@ -326,6 +328,142 @@ describe('preload', () => {
326
328
} )
327
329
} )
328
330
} )
331
+
332
+ it ( 'should preload content retrieved with files.ls' , done => {
333
+ let dirCid
334
+
335
+ waterfall ( [
336
+ cb => ipfs . add ( { path : `/t/${ hat ( ) } ` , content : Buffer . from ( hat ( ) ) } , cb ) ,
337
+ ( res , cb ) => {
338
+ dirCid = res [ res . length - 1 ] . hash
339
+ MockPreloadNode . waitForCids ( dirCid , cb )
340
+ } ,
341
+ cb => MockPreloadNode . clearPreloadCids ( cb ) ,
342
+ cb => ipfs . files . ls ( `/ipfs/${ dirCid } ` , err => cb ( err ) ) ,
343
+ cb => MockPreloadNode . waitForCids ( `/ipfs/${ dirCid } ` , cb )
344
+ ] , done )
345
+ } )
346
+
347
+ it ( 'should preload content retrieved with files.ls by CID' , done => {
348
+ let dirCid
349
+
350
+ waterfall ( [
351
+ cb => ipfs . add ( { path : `/t/${ hat ( ) } ` , content : Buffer . from ( hat ( ) ) } , cb ) ,
352
+ ( res , cb ) => {
353
+ dirCid = res [ res . length - 1 ] . hash
354
+ MockPreloadNode . waitForCids ( dirCid , cb )
355
+ } ,
356
+ cb => MockPreloadNode . clearPreloadCids ( cb ) ,
357
+ cb => ipfs . files . ls ( new CID ( dirCid ) , err => cb ( err ) ) ,
358
+ cb => MockPreloadNode . waitForCids ( dirCid , cb )
359
+ ] , done )
360
+ } )
361
+
362
+ it ( 'should preload content retrieved with files.lsReadableStream' , done => {
363
+ let dirCid
364
+
365
+ waterfall ( [
366
+ cb => ipfs . add ( { path : `/t/${ hat ( ) } ` , content : Buffer . from ( hat ( ) ) } , cb ) ,
367
+ ( res , cb ) => {
368
+ dirCid = res [ res . length - 1 ] . hash
369
+ MockPreloadNode . waitForCids ( dirCid , cb )
370
+ } ,
371
+ cb => MockPreloadNode . clearPreloadCids ( cb ) ,
372
+ cb => {
373
+ ipfs . files . lsReadableStream ( `/ipfs/${ dirCid } ` )
374
+ . on ( 'data' , ( ) => { } )
375
+ . on ( 'error' , cb )
376
+ . on ( 'end' , cb )
377
+ } ,
378
+ cb => MockPreloadNode . waitForCids ( `/ipfs/${ dirCid } ` , cb )
379
+ ] , done )
380
+ } )
381
+
382
+ it ( 'should preload content retrieved with files.lsPullStream' , done => {
383
+ let dirCid
384
+
385
+ waterfall ( [
386
+ cb => ipfs . add ( { path : `/t/${ hat ( ) } ` , content : Buffer . from ( hat ( ) ) } , cb ) ,
387
+ ( res , cb ) => {
388
+ dirCid = res [ res . length - 1 ] . hash
389
+ MockPreloadNode . waitForCids ( dirCid , cb )
390
+ } ,
391
+ cb => MockPreloadNode . clearPreloadCids ( cb ) ,
392
+ cb => pull (
393
+ ipfs . files . lsPullStream ( `/ipfs/${ dirCid } ` ) ,
394
+ pull . onEnd ( cb )
395
+ ) ,
396
+ cb => MockPreloadNode . waitForCids ( `/ipfs/${ dirCid } ` , cb )
397
+ ] , done )
398
+ } )
399
+
400
+ it ( 'should preload content retrieved with files.read' , done => {
401
+ let fileCid
402
+
403
+ waterfall ( [
404
+ cb => ipfs . add ( Buffer . from ( hat ( ) ) , cb ) ,
405
+ ( res , cb ) => {
406
+ fileCid = res [ 0 ] . hash
407
+ MockPreloadNode . waitForCids ( fileCid , cb )
408
+ } ,
409
+ cb => MockPreloadNode . clearPreloadCids ( cb ) ,
410
+ cb => ipfs . files . read ( `/ipfs/${ fileCid } ` , err => cb ( err ) ) ,
411
+ cb => MockPreloadNode . waitForCids ( `/ipfs/${ fileCid } ` , cb )
412
+ ] , done )
413
+ } )
414
+
415
+ it ( 'should preload content retrieved with files.readReadableStream' , done => {
416
+ let fileCid
417
+
418
+ waterfall ( [
419
+ cb => ipfs . add ( Buffer . from ( hat ( ) ) , cb ) ,
420
+ ( res , cb ) => {
421
+ fileCid = res [ 0 ] . hash
422
+ MockPreloadNode . waitForCids ( fileCid , cb )
423
+ } ,
424
+ cb => MockPreloadNode . clearPreloadCids ( cb ) ,
425
+ cb => {
426
+ ipfs . files . readReadableStream ( `/ipfs/${ fileCid } ` )
427
+ . on ( 'data' , ( ) => { } )
428
+ . on ( 'error' , cb )
429
+ . on ( 'end' , cb )
430
+ } ,
431
+ cb => MockPreloadNode . waitForCids ( `/ipfs/${ fileCid } ` , cb )
432
+ ] , done )
433
+ } )
434
+
435
+ it ( 'should preload content retrieved with files.readPullStream' , done => {
436
+ let fileCid
437
+
438
+ waterfall ( [
439
+ cb => ipfs . add ( Buffer . from ( hat ( ) ) , cb ) ,
440
+ ( res , cb ) => {
441
+ fileCid = res [ 0 ] . hash
442
+ MockPreloadNode . waitForCids ( fileCid , cb )
443
+ } ,
444
+ cb => MockPreloadNode . clearPreloadCids ( cb ) ,
445
+ cb => pull (
446
+ ipfs . files . readPullStream ( `/ipfs/${ fileCid } ` ) ,
447
+ pull . onEnd ( cb )
448
+ ) ,
449
+ cb => MockPreloadNode . waitForCids ( `/ipfs/${ fileCid } ` , cb )
450
+ ] , done )
451
+ } )
452
+
453
+ it ( 'should preload content retrieved with files.stat' , done => {
454
+ let fileCid
455
+
456
+ waterfall ( [
457
+ cb => ipfs . add ( Buffer . from ( hat ( ) ) , cb ) ,
458
+ ( res , cb ) => {
459
+ fileCid = res [ 0 ] . hash
460
+ MockPreloadNode . waitForCids ( fileCid , cb )
461
+ } ,
462
+ cb => MockPreloadNode . clearPreloadCids ( cb ) ,
463
+ cb => ipfs . files . stat ( `/ipfs/${ fileCid } ` , err => cb ( err ) ) ,
464
+ cb => MockPreloadNode . waitForCids ( `/ipfs/${ fileCid } ` , cb )
465
+ ] , done )
466
+ } )
329
467
} )
330
468
331
469
describe ( 'preload disabled' , function ( ) {
0 commit comments