forked from ipfs/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.js
33 lines (28 loc) · 770 Bytes
/
1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict'
const series = require('async/series')
const IPFS = require('ipfs')
const node = new IPFS()
let fileMultihash
series([
(cb) => node.on('ready', cb),
(cb) => node.version((err, version) => {
if (err) { return cb(err) }
console.log('Version:', version.version)
cb()
}),
(cb) => node.files.add({
path: 'hello.txt',
content: Buffer.from('Hello World 101')
}, (err, result) => {
if (err) { return cb(err) }
console.log('\nAdded file:', result[0].path, result[0].hash)
fileMultihash = result[0].hash
cb()
}),
(cb) => node.files.cat(fileMultihash, (err, stream) => {
if (err) { return cb(err) }
console.log('\nFile content:')
stream.pipe(process.stdout)
stream.on('end', process.exit)
})
])