This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Replaces the async npm package with vanilla JavaScript. License: MIT Signed-off-by: David Gilbertson <gilbertson.david@gmail.com>
- Loading branch information
1 parent
57f977f
commit 80ae33e
Showing
4 changed files
with
67 additions
and
65 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,22 @@ | ||
'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({ | ||
|
||
node.on('ready', async () => { | ||
const version = await node.version() | ||
|
||
console.log('Version:', version.version) | ||
|
||
const filesAdded = await node.files.add({ | ||
path: 'hello.txt', | ||
content: Buffer.from('Hello World 101') | ||
}, (err, filesAdded) => { | ||
if (err) { return cb(err) } | ||
|
||
console.log('\nAdded file:', filesAdded[0].path, filesAdded[0].hash) | ||
fileMultihash = filesAdded[0].hash | ||
cb() | ||
}), | ||
(cb) => node.files.cat(fileMultihash, (err, data) => { | ||
if (err) { return cb(err) } | ||
|
||
console.log('\nFile content:') | ||
process.stdout.write(data) | ||
}) | ||
]) | ||
|
||
console.log('Added file:', filesAdded[0].path, filesAdded[0].hash) | ||
|
||
const fileBuffer = await node.files.cat(filesAdded[0].hash) | ||
|
||
console.log('Added file contents:', fileBuffer.toString()) | ||
}) |
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
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