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

Commit

Permalink
Merge branch 'master' into logging-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pkafei authored Dec 4, 2018
2 parents 8ee5865 + d215502 commit b2c784d
Show file tree
Hide file tree
Showing 114 changed files with 2,657 additions and 945 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ WORKDIR /usr/src/app
COPY . /usr/src/app

ENV IPFS_WRTC_LINUX_WINDOWS=1
ENV IPFS_BOOTSTRAP=1
ENV IPFS_MONITORING=1
ENV IPFS_PATH=/root/.jsipfs
ENV IPFS_API_HOST=0.0.0.0
Expand Down
116 changes: 62 additions & 54 deletions README.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- [ ] [peer-star-app](https://github.com/ipfs-shipyard/peer-star-app)
- [ ] [ipfs-log](https://github.com/orbitdb/ipfs-log)
- [ ] [orbit-db](https://github.com/orbitdb/orbit-db)
- [ ] [service-worker-gateway](https://github.com/ipfs-shipyard/service-worker-gateway)
- Documentation
- [ ] Ensure that README.md is up to date
- [ ] Ensure that all the examples run
Expand All @@ -46,10 +47,10 @@
Would you like to contribute to the IPFS project and don't know how? Well, there are a few places you can get started:
- Check the issues with the `help wanted` label at the Ready column in our waffle board - https://waffle.io/ipfs/js-ipfs?label=help%20wanted
- Join an IPFS All Hands, introduce yourself and let us know where you would like to contribute - https://github.com/ipfs/pm/#all-hands-call
- Join an IPFS All Hands, introduce yourself and let us know where you would like to contribute - https://github.com/ipfs/team-mgmt/#weekly-ipfs-all-hands
- Hack with IPFS and show us what you made! The All Hands call is also the perfect venue for demos, join in and show us what you built
- Join the discussion at http://discuss.ipfs.io/ and help users finding their answers.
- Join the [⚡️ⒿⓈ Core Dev Team Weekly Sync 🙌🏽](https://github.com/ipfs/pm/issues/650) and be part of the Sprint action!
- Join the [⚡️ⒿⓈ Core Dev Team Weekly Sync 🙌🏽](https://github.com/ipfs/team-mgmt/issues/650) and be part of the Sprint action!
# ⁉️ Do you have questions?
Expand Down
5 changes: 4 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Let us know if you find any issue or if you want to contribute and add a new tut
## Examples

- [js-ipfs in the browser with Browserify](./browser-browserify)
- [js-ipfs in the browser with Parcel.js](./browser-parceljs)
- [js-ipfs in the browser with WebPack](./browser-webpack)
- [js-ipfs in the browser with a `<script>` tag](./browser-script-tag)
- [js-ipfs in electron](./run-in-electron)
Expand All @@ -31,7 +32,9 @@ Let us know if you find any issue or if you want to contribute and add a new tut

In this section, you will find explanations to different pieces of IPFS Architecture and how `js-ipfs` implements them.

![](../img/core.png)
![](../img/architecture.png)

[Annotated version](https://user-images.githubusercontent.com/1211152/47606420-b6265780-da13-11e8-923b-b365a8534e0e.png)

> These explanations are still a work in progress
Expand Down
4 changes: 2 additions & 2 deletions examples/browser-add-readable-stream/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Using duplex streams to add files to IPFS in the browser

If you have a number of files that you'd like to add to IPFS and end up with a hash representing the directory containing your files, you can invoke [`ipfs.files.add`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#add) with an array of objects.
If you have a number of files that you'd like to add to IPFS and end up with a hash representing the directory containing your files, you can invoke [`ipfs.add`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#add) with an array of objects.

But what if you don't know how many there will be in advance? You can add multiple files to a directory in IPFS over time by using [`ipfs.files.addReadableStream`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addreadablestream).
But what if you don't know how many there will be in advance? You can add multiple files to a directory in IPFS over time by using [`ipfs.addReadableStream`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addreadablestream).

See `index.js` for a working example and open `index.html` in your browser to see it run.
2 changes: 1 addition & 1 deletion examples/browser-add-readable-stream/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const createFiles = (directory) => {

const streamFiles = (directory, files, cb) => {
// Create a stream to write files to
const stream = ipfs.files.addReadableStream()
const stream = ipfs.addReadableStream()
stream.on('data', function (data) {
log(`Added ${data.path} hash: ${data.hash}`)

Expand Down
4 changes: 2 additions & 2 deletions examples/browser-browserify/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ node.once('ready', () => console.log('IPFS node is ready'))
function store () {
const toStore = document.getElementById('source').value

node.files.add(Buffer.from(toStore), (err, res) => {
node.add(Buffer.from(toStore), (err, res) => {
if (err || !res) {
return console.error('ipfs add error', err, res)
}
Expand All @@ -25,7 +25,7 @@ function store () {

function display (hash) {
// buffer: true results in the returned result being a buffer rather than a stream
node.files.cat(hash, (err, data) => {
node.cat(hash, (err, data) => {
if (err) { return console.error('ipfs cat error', err) }

document.getElementById('hash').innerText = hash
Expand Down
4 changes: 4 additions & 0 deletions examples/browser-parceljs/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["syntax-async-functions","transform-regenerator"]
}
6 changes: 6 additions & 0 deletions examples/browser-parceljs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist/
/node_modules/
.nvmrc
.cache
npm-debug.log
.DS_Store
38 changes: 38 additions & 0 deletions examples/browser-parceljs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Bundle js-ipfs with [Parcel.js](https://parceljs.org/)

> In this example, you will find a boilerplate application that connects to
IPFS using JS-IPFS and is bundled with [Parcel.js](https://parceljs.org/), so
that you can follow it for creating Parcel.js bundled js-ipfs DApps.

## Before you start

1. Start your IPFS daemon of choice e.g. `ipfs daemon` (optional if you do not
want to serve the example over IPFS)
1. Open a new terminal
1. `cd` into this folder
1. Run `npm install`

## Running this example in development mode with auto-reloading

1. `npm start`
1. Open your browser at `http://localhost:1234`

You should see the following:

![](https://ipfs.io/ipfs/QmSiZ18GffagbbJ3z72kK7u3SP9MXqBB1vrU1KFYP3GMYs/1.png)

## Build and add to IPFS

1. Clear the contents of `dist` if this is not the first time you are building
e.g. `rm -r dist` on a unix system
1. `npm run build`
1. The production build of the site is now in the `dist` folder
1. Add the folder to ipfs using your IPFS client of choice e.g.
`ipfs add -r dist`

The last hash output is the hash of the directory. This can be used to access
this example served over IPFS and will be accessible by a public gateway:

> https://ipfs.io/ipfs/<hash_of_directory>/

Binary file added examples/browser-parceljs/img/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions examples/browser-parceljs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "browser-parceljs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"browserslist": [
"last 2 Chrome versions"
],
"scripts": {
"lint": "standard public/**/*.js",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "parcel public/index.html",
"build": "parcel build public/index.html --public-url ./"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ipfs": "file:../../"
},
"devDependencies": {
"@babel/cli": "^7.1.5",
"@babel/core": "^7.1.6",
"@babel/preset-env": "^7.1.6",
"babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-polyfill": "^6.26.0",
"parcel-bundler": "^1.10.3",
"standard": "^12.0.1"
}
}
23 changes: 23 additions & 0 deletions examples/browser-parceljs/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>

<html lang="en">

<head>
<meta charset="utf-8">
<title>js-ipfs parcel.js browser example</title>
</head>

<body>
<header>
<h1 id="status">Connecting to IPFS...</h1>
</header>

<main>
<pre id="output"></pre>
</main>

<script src="./index.js"></script>

</body>

</html>
35 changes: 35 additions & 0 deletions examples/browser-parceljs/public/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'babel-polyfill'
import IPFS from 'ipfs'

// IPFS node setup
const node = new IPFS({ repo: String(Math.random() + Date.now()) })

// UI elements
const status = document.getElementById('status')
const output = document.getElementById('output')

output.textContent = ''

function log (txt) {
console.info(txt)
output.textContent += `${txt.trim()}\n`
}

node.on('ready', async () => {
status.innerText = 'Connected to IPFS :)'

const version = await node.version()

log(`The IPFS node version is ${version.version}`)

const filesAdded = await node.add({
path: 'hello-parcel.txt',
content: Buffer.from('Hello from parcel.js bundled ipfs example')
})

log(`This page deployed ${filesAdded[0].path} to IPFS and its hash is ${filesAdded[0].hash}`)

const fileBuffer = await node.cat(filesAdded[0].hash)

log(`The contents of the file was: ${fileBuffer.toString()}`)
})
2 changes: 1 addition & 1 deletion examples/browser-readablestream/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ipfs.on('ready', () => {
}

// This stream will contain the requested bytes
stream = ipfs.files.catReadableStream(hashInput.value.trim(), {
stream = ipfs.catReadableStream(hashInput.value.trim(), {
offset: start,
length: end && end - start
})
Expand Down
2 changes: 1 addition & 1 deletion examples/browser-readablestream/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const dragDrop = (ipfs) => {

const reader = new window.FileReader()
reader.onload = (event) => {
ipfs.files.add({
ipfs.add({
path: file.name,
content: ipfs.types.Buffer.from(event.target.result)
}, {
Expand Down
8 changes: 4 additions & 4 deletions examples/browser-script-tag/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

document.getElementById("status").innerHTML= 'Node status: ' + (node.isOnline() ? 'online' : 'offline')

// You can write more code here to use it. Use methods like
// node.files.add, node.files.get. See the API docs here:
// You can write more code here to use it. Use methods like
// node.add, node.get. See the API docs here:
// https://github.com/ipfs/interface-ipfs-core
})
</script>
Expand All @@ -28,7 +28,7 @@ <h2>Some suggestions</h2>
<p>Try adding a new file:</p>

<code style="display:block; white-space:pre-wrap; background-color:#d7d6d6">
node.files.add(new node.types.Buffer('Hello world!'), (err, filesAdded) => {
node.add(new node.types.Buffer('Hello world!'), (err, filesAdded) => {
if (err) {
return console.error('Error - ipfs add', err, res)
}
Expand All @@ -40,7 +40,7 @@ <h2>Some suggestions</h2>
<p>You can cat that same file. If you used the exact same string as above ('Hello world!') you should have an hash like this: 'QmQzCQn4puG4qu8PVysxZmscmQ5vT1ZXpqo7f58Uh9QfyY'</p>

<code style="display:block; white-space:pre-wrap; background-color:#d7d6d6">
node.files.cat('QmQzCQn4puG4qu8PVysxZmscmQ5vT1ZXpqo7f58Uh9QfyY', function (err, data) {
node.cat('QmQzCQn4puG4qu8PVysxZmscmQ5vT1ZXpqo7f58Uh9QfyY', function (err, data) {
if (err) {
return console.error('Error - ipfs files cat', err, res)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/browser-webpack/src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class App extends React.Component {
})
})

node.files.add([Buffer.from(stringToUse)], (err, filesAdded) => {
node.add([Buffer.from(stringToUse)], (err, filesAdded) => {
if (err) { throw err }

const hash = filesAdded[0].hash
self.setState({ added_file_hash: hash })

node.files.cat(hash, (err, data) => {
node.cat(hash, (err, data) => {
if (err) { throw err }
self.setState({ added_file_contents: data.toString() })
})
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-ipfs-repo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ node.on('ready', () => {
})
// Once we have the version, let's add a file to IPFS
.then(() => {
return node.files.add({
return node.add({
path: 'test-data.txt',
content: Buffer.from('We are using a customized repo!')
})
})
// Log out the added files metadata and cat the file from IPFS
.then((filesAdded) => {
console.log('\nAdded file:', filesAdded[0].path, filesAdded[0].hash)
return node.files.cat(filesAdded[0].hash)
return node.cat(filesAdded[0].hash)
})
// Print out the files contents to console
.then((data) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-libp2p/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const IPFS = require('ipfs')
const TCP = require('libp2p-tcp')
const MulticastDNS = require('libp2p-mdns')
const WebSocketStar = require('libp2p-websocket-star')
const Bootstrap = require('libp2p-railing')
const Bootstrap = require('libp2p-bootstrap')
const SPDY = require('libp2p-spdy')
const KadDHT = require('libp2p-kad-dht')
const MPLEX = require('libp2p-mplex')
Expand Down
16 changes: 8 additions & 8 deletions examples/custom-libp2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"license": "MIT",
"dependencies": {
"ipfs": "file:../../",
"libp2p": "~0.22.0",
"libp2p-kad-dht": "~0.10.1",
"libp2p": "~0.24.0",
"libp2p-bootstrap": "~0.9.3",
"libp2p-kad-dht": "~0.11.1",
"libp2p-mdns": "~0.12.0",
"libp2p-mplex": "~0.8.0",
"libp2p-railing": "~0.9.2",
"libp2p-secio": "~0.10.0",
"libp2p-spdy": "~0.12.1",
"libp2p-tcp": "~0.12.0",
"libp2p-websocket-star": "~0.8.1"
"libp2p-mplex": "~0.8.4",
"libp2p-secio": "~0.10.1",
"libp2p-spdy": "~0.13.0",
"libp2p-tcp": "~0.13.0",
"libp2p-websocket-star": "~0.9.0"
}
}
4 changes: 2 additions & 2 deletions examples/exchange-files-in-browser/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function getFile () {

FILES.push(hash)

node.files.get(hash)
node.get(hash)
.then((files) => {
files.forEach((file) => {
if (file.content) {
Expand Down Expand Up @@ -206,7 +206,7 @@ function onDrop (event) {
.then((buffer) => {
fileSize = file.size

node.files.add({
node.add({
path: file.name,
content: Buffer.from(buffer)
}, { wrap: true, progress: updateProgress }, (err, filesAdded) => {
Expand Down
4 changes: 2 additions & 2 deletions examples/ipfs-101/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ node.on('ready', async () => {

console.log('Version:', version.version)

const filesAdded = await node.files.add({
const filesAdded = await node.add({
path: 'hello.txt',
content: Buffer.from('Hello World 101')
})

console.log('Added file:', filesAdded[0].path, filesAdded[0].hash)

const fileBuffer = await node.files.cat(filesAdded[0].hash)
const fileBuffer = await node.cat(filesAdded[0].hash)

console.log('Added file contents:', fileBuffer.toString())
})
Loading

0 comments on commit b2c784d

Please sign in to comment.