2017-09-08 12 views
0

IPFS javascriptライブラリを使用してcatメソッドが私のために働いていないことを証明するためにこのテストケースを作成しました。私は間違って何をしていますか?私のコンソール出力は、(err、filestream)コールバックがまったく呼び出されていないかのように、 'node.files.cat'関数内から何も描画されません。私はマルチハッシュが多少動作していることを知っています。私がそれを変更した場合、私は致命的なエラーが発生するからです。しかし今のところ、NODE READYの後にはちょうどロックされ、一時停止しています。Javascriptの 'cat'関数のIPFSが機能しない

const IPFS = require('ipfs') 
const path = require('path') 
const os = require('os') 
const fs = require('fs') 

console.log('ipfs test ') 


var mhash = "Qmc5LfkMVAhvzip2u2RjRBRhgVthtSokHsz4Y5bgaBCW2R"; 


// Create the IPFS node instance 
const node = new IPFS() 

node.on('ready',() => { 

    // Your node is now ready to use \o/ 


    console.log('NODE READY') 



/* 
THIS WORKS 
    var test_rstream = fs.createReadStream(path.join(__dirname, '.', '/public/sample_land_file.json')) 
    var wstream = fs.createWriteStream(os.tmpdir() + '/lobc_cache/'+'Qmc5LfkMVAhvzip2u2RjRBRhgVthtSokHsz4Y5bgaBCW2R'); 


     wstream.on('finish', function() { 
     console.log('Written ' + wstream.bytesWritten + ' ' + wstream.path); 
     test_rstream.close() 
     }); 

     test_rstream.pipe(wstream); 

*/ 


    node.files.cat("Qmc5LfkMVAhvzip2u2RjRBRhgVthtSokHsz4Y5bgaBCW2R", function (err, filestream) { 

      console.log('WHY ISNT THIS FIRING ') // i never see this logged 
     console.log(filestream) 

     console.log(os.tmpdir()) 


     if (!fs.existsSync(os.tmpdir() + '/lobc_cache')){ 
      fs.mkdirSync(os.tmpdir() + '/lobc_cache'); 
     } 

     var wstream = fs.createWriteStream(os.tmpdir() + '/lobc_cache/'+'Qmc5LfkMVAhvzip2u2RjRBRhgVthtSokHsz4Y5bgaBCW2R'); 



     result = ''; 


      wstream.on('finish', function() { 
      console.log('Written ' + wstream.bytesWritten + ' ' + wstream.path); 
      filestream.close() 
      }); 


       filestream.pipe(wstream); 

       // wstream.end(); 
    // file will be a stream containing the data of the file requested 
    }) 





    // stopping a node 
    node.stop(() => { 
    // node is now 'offline' 
    }) 
}) 


node.on('start',() => { 

    console.log('NODE START') 
}) 

答えて

0

これはバグのようです。これを簡単に解決するには、node.files.catを.on( 'ready')のコールバックの中に置くだけです。ノードがのオンラインの前にビットマップが要求を破棄しているようです。

これが動作するかどうかを教えてください。

関連する問題