This repository was 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.
Merge branch 'master' into logging-bug
- Loading branch information
Showing
114 changed files
with
2,657 additions
and
945 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
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
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,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. |
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
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,4 @@ | ||
{ | ||
"presets": ["@babel/preset-env"], | ||
"plugins": ["syntax-async-functions","transform-regenerator"] | ||
} |
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,6 @@ | ||
dist/ | ||
/node_modules/ | ||
.nvmrc | ||
.cache | ||
npm-debug.log | ||
.DS_Store |
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,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: | ||
|
||
 | ||
|
||
## 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>/ | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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" | ||
} | ||
} |
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,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> |
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,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()}`) | ||
}) |
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
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
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
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
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
Oops, something went wrong.