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.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lint and polish): add a little more comments
- Loading branch information
Showing
3 changed files
with
84 additions
and
40 deletions.
There are no files selected for viewing
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
'use strict' | ||
|
||
const IPFS = require('../../src/core') // replace this by line below | ||
// const IPFS = require('ipfs') | ||
|
||
/* | ||
* Create a new IPFS instance, using default repo (fs) on default path (~/.ipfs) | ||
*/ | ||
const node = new IPFS() | ||
|
||
const fs = require('fs') | ||
|
||
/* | ||
* Display version of js-ipfs | ||
*/ | ||
node.version(gotVersion) | ||
|
||
function gotVersion (err, version) { | ||
if (err) { | ||
return console.error(err) | ||
} | ||
|
||
console.log(version) | ||
|
||
/* | ||
* Load the config into memory (generate the Public Key from the Private Key) | ||
*/ | ||
node.load((err) => { | ||
if (err) { | ||
return console.log(err) | ||
} | ||
console.log('Repo was loaded\n') | ||
|
||
/* | ||
* Our instance is set, now let's goOnline (turn on bitswap) and do cool | ||
* stuff | ||
*/ | ||
|
||
node.goOnline((err) => { | ||
if (err) { | ||
return console.log(err) | ||
} | ||
|
||
// We can test to see if we actually are online if we want to | ||
if (node.isOnline()) { | ||
console.log('\nYep, we are online') | ||
} | ||
|
||
/* | ||
* Add a file to IPFS - Complete Files API on: | ||
* https://github.com/ipfs/interface-ipfs-core/tree/master/API/files | ||
*/ | ||
|
||
const file = { | ||
path: 'hello.txt', | ||
content: fs.createReadStream('./hello.txt') | ||
} | ||
|
||
node.files.add(file, (err, result) => { | ||
if (err) { | ||
return console.error(err) | ||
} | ||
|
||
/* | ||
* Awesome we've added a file so let's retrieve and | ||
* display its contents from IPFS | ||
*/ | ||
|
||
console.log('\n', result, '\n') | ||
|
||
node.files.cat(result[0].hash, (err, stream) => { | ||
if (err) { | ||
return console.error(err) | ||
} | ||
|
||
console.log('file content: \n') | ||
|
||
stream.pipe(process.stdout) | ||
stream.on('end', process.exit) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.