Created
February 1, 2017 11:42
-
-
Save gerhardberger/478c13b27b6acaf5709257cf6838947d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const os = require('os') | |
const path = require('path') | |
const IPFS = require('ipfs') | |
const fileMultihash = process.argv[2] | |
const node = new IPFS(path.join(os.tmpDir() + '/' + new Date().toString())) | |
node.version((err, version) => { | |
if (err) return console.error(err) | |
console.log('IPFS Version:', version.version) | |
node.init({ emptyRepo: true, bits: 2048 }, err => { | |
if (err) return console.error(err) | |
node.load(err => { | |
if (err) return console.error(err) | |
node.goOnline(err => { | |
if (err) return console.error(err) | |
console.log('Node is online') | |
if (node.isOnline()) { | |
console.log('Node is now ready and online') | |
node.files.cat(fileMultihash, (err, stream) => { | |
if (err) return console.error(err) | |
console.log('File content:') | |
stream.pipe(process.stdout) | |
stream.on('end', process.exit) | |
}) | |
} | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment