Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Add a few examples to README.md #534

Closed
wants to merge 8 commits into from
Closed
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ This project is available through [npm](https://www.npmjs.com/). To install:
$ npm install ipfs --save
```

Requires npm@3 and node >= 4, tested on OSX & Linux, expected to work on Windows.

### Use in Node.js

To include this project programmatically:
Expand Down Expand Up @@ -110,8 +112,40 @@ The last published version of the package become [available for download](htt

### Examples

> **Will come soon**
```js
var fs = require('fs');
var promisify = require('promisify-es6')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable promisify does not seem to be used anywhere below in your examples.

(Should you decide to delete this line?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove that line. Thank you.


var IPFS = require('ipfs')
var node = new IPFS()

function displayVersion() {
console.log(node.version());
}

function initializeRepo() {
node.init(function(err){
console.log(err);
})
}

function startDaemon() {
node.goOnline(function(msg) {});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably call addFile in the callback to trigger the interaction once the node is online.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix this up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that you would go online do some work and then go offline.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my thought at least, did you have something else in mind?

}

function addFile() {
var readStream = fs.createReadStream('PathOfFileToAdd');
node.files.add(readStream).then(function(hash) {
console.log(hash);
});
}

function catFile() {
node.files.cat('HashOfExistingFile').then(function(stream) {
stream.pipe(process.stdout, { end : false });
});
}
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the code style to be consistent with our code base, i.e standard

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback. I will read the standard and apply.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :)

### API

A complete API definition will come, meanwhile, you can learn how to you use js-ipfs throught he standard interface at [![](https://img.shields.io/badge/interface--ipfs--core-API%20Docs-blue.svg)](https://github.com/ipfs/interface-ipfs-core)
Expand Down