Created
February 1, 2017 21:17
-
-
Save gerhardberger/6593eca682b58f9af28da774c63671c7 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 { createWriteStream } = require('fs') | |
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.get(fileMultihash, (err, stream) => { | |
if (err) return console.error(err) | |
// console.log('File content:') | |
// stream.pipe(process.stdout) | |
// stream.on('end', process.exit) | |
stream.on('data', (file) => { | |
// write the file's path and contents to standard out | |
console.log(file.path) | |
file.content.pipe(createWriteStream('x' + file.path)) | |
file.content.on('end', () => process.exit(0)) | |
}) | |
}) | |
} | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment