deps: update it-length-prefix, uint8arraylist etc (#1317)

In order to support no-copy operations in streams, update all deps
to support streaming Uint8ArrayLists.
This commit is contained in:
Alex Potsides
2022-08-03 14:15:35 +01:00
committed by GitHub
parent 05e8e7ead9
commit 564f4b8aa7
27 changed files with 69 additions and 58 deletions

View File

@ -1,5 +1,5 @@
import path from 'path'
import execa from 'execa'
import { execa } from 'execa'
import pDefer from 'p-defer'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { fileURLToPath } from 'url'

View File

@ -28,7 +28,7 @@ export function streamToConsole(stream) {
// Decode length-prefixed data
lp.decode(),
// Turn buffers into strings
(source) => map(source, (buf) => uint8ArrayToString(buf)),
(source) => map(source, (buf) => uint8ArrayToString(buf.subarray())),
// Sink function
async function (source) {
// For each chunk of data

View File

@ -1,5 +1,5 @@
import path from 'path'
import execa from 'execa'
import { execa } from 'execa'
import pDefer from 'p-defer'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { fileURLToPath } from 'url'

View File

@ -1,5 +1,5 @@
import path from 'path'
import execa from 'execa'
import { execa } from 'execa'
import pWaitFor from 'p-wait-for'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { fileURLToPath } from 'url'

View File

@ -1,5 +1,5 @@
import path from 'path'
import execa from 'execa'
import { execa } from 'execa'
import pWaitFor from 'p-wait-for'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { fileURLToPath } from 'url'

View File

@ -1,5 +1,5 @@
import path from 'path'
import execa from 'execa'
import { execa } from 'execa'
import pDefer from 'p-defer'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { fileURLToPath } from 'url'

View File

@ -1,6 +1,6 @@
# libp2p in the browser
This example leverages the [Parcel.js bundler](https://parceljs.org/) to compile and serve the libp2p code in the browser. Parcel uses [Babel](https://babeljs.io/) to handle transpilation of the code. You can use other bundlers such as Webpack or Browserify, but we will not be covering them here.
This example leverages the [vite bundler](https://vitejs.dev/) to compile and serve the libp2p code in the browser. You can use other bundlers such as Webpack, but we will not be covering them here.
## Setup
@ -18,7 +18,7 @@ npm install
## Running the examples
Start by running the Parcel server:
Start by running the vite server:
```
npm start
@ -30,7 +30,7 @@ The output should look something like this:
$ npm start
> libp2p-in-browser@1.0.0 start
> parcel index.html
> vite index.html
Server running at http://localhost:1234
✨ Built in 1000ms.
@ -40,7 +40,7 @@ This will compile the code and start a server listening on port [http://localhos
Now, if you open a second browser tab to `http://localhost:1234`, you should discover your node from the previous tab. This is due to the fact that the `libp2p-webrtc-star` transport also acts as a Peer Discovery interface. Your node will be notified of any peer that connects to the same signaling server you are connected to. Once libp2p discovers this new peer, it will attempt to establish a direct WebRTC connection.
**Note**: In the example we assign libp2p to `window.libp2p`, in case you would like to play around with the API directly in the browser. You can of course make changes to `index.js` and Parcel will automatically rebuild and reload the browser tabs.
**Note**: In the example we assign libp2p to `window.libp2p`, in case you would like to play around with the API directly in the browser. You can of course make changes to `index.js` and vite will automatically rebuild and reload the browser tabs.
## Going to production?

View File

@ -4,7 +4,7 @@
<head>
<meta charset="utf-8">
<title>js-libp2p parcel.js browser example</title>
<title>js-libp2p vite browser example</title>
</head>
<body>

View File

@ -1,4 +1,4 @@
import execa from 'execa'
import { execa } from 'execa'
import { chromium } from 'playwright'
import path from 'path'
import { fileURLToPath } from 'url'

View File

@ -9,13 +9,13 @@
},
"license": "MIT",
"dependencies": {
"@libp2p/pubsub-peer-discovery": "^6.0.0",
"@libp2p/floodsub": "^3.0.0",
"@libp2p/pubsub-peer-discovery": "^6.0.1",
"@libp2p/floodsub": "^3.0.3",
"@nodeutils/defaults-deep": "^1.1.0",
"execa": "^2.1.0",
"fs-extra": "^8.1.0",
"execa": "^6.1.0",
"fs-extra": "^10.1.0",
"libp2p": "../",
"p-defer": "^3.0.0",
"p-defer": "^4.0.0",
"uint8arrays": "^3.0.0",
"which": "^2.0.1"
},

View File

@ -1,5 +1,5 @@
import path from 'path'
import execa from 'execa'
import { execa } from 'execa'
import pDefer from 'p-defer'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { fileURLToPath } from 'url'

View File

@ -1,5 +1,5 @@
import path from 'path'
import execa from 'execa'
import { execa } from 'execa'
import pDefer from 'p-defer'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { fileURLToPath } from 'url'

View File

@ -3,7 +3,7 @@ process.env.CI = true // needed for some "clever" build tools
import fs from 'fs-extra'
import path from 'path'
import execa from 'execa'
import { execa } from 'execa'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
@ -36,7 +36,8 @@ async function installDeps (dir) {
return
}
const proc = execa.command('npm install', {
const proc = execa('npm', ['install'], {
all: true,
cwd: dir
})
proc.all.on('data', (data) => {
@ -71,6 +72,7 @@ async function build (dir) {
}
const proc = execa('npm', ['run', build], {
all: true,
cwd: dir
})
proc.all.on('data', (data) => {

View File

@ -1,4 +1,4 @@
import execa from 'execa'
import { execa } from 'execa'
import fs from 'fs-extra'
import which from 'which'
@ -26,7 +26,10 @@ export async function waitForOutput (expectedOutput, command, args = [], opts =
command = 'node'
}
const proc = execa(command, args, opts)
const proc = execa(command, args, {
...opts,
all: true
})
let output = ''
let time = 600000

View File

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js-libp2p parcel.js browser example</title>
<title>js-libp2p vite browser example</title>
</head>
<body>

View File

@ -10,9 +10,9 @@
"license": "ISC",
"dependencies": {
"@libp2p/webrtc-direct": "^2.0.0",
"@chainsafe/libp2p-noise": "^7.0.1",
"@chainsafe/libp2p-noise": "^7.0.3",
"@libp2p/bootstrap": "^2.0.0",
"@libp2p/mplex": "^4.0.2",
"@libp2p/mplex": "^4.0.3",
"libp2p": "../../",
"wrtc": "^0.4.7"
},

View File

@ -1,5 +1,5 @@
import path from 'path'
import execa from 'execa'
import { execa } from 'execa'
import pDefer from 'p-defer'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { chromium } from 'playwright'