mirror of
https://github.com/aljazceru/pear-docs.git
synced 2025-12-17 22:44:21 +01:00
api alignment
This commit is contained in:
@@ -22,12 +22,14 @@ Create the `writer-app` project with these commands:
|
|||||||
mkdir writer-app
|
mkdir writer-app
|
||||||
cd writer-app
|
cd writer-app
|
||||||
pear init -y -t terminal
|
pear init -y -t terminal
|
||||||
npm install hypercore hyperswarm b4a
|
npm install bare-path bare-process hypercore hyperswarm b4a
|
||||||
```
|
```
|
||||||
|
|
||||||
Alter the generated `writer-app/index.js` file to the following:
|
Alter the generated `writer-app/index.js` file to the following:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
import path from 'bare-path'
|
||||||
|
import process from 'bare-process'
|
||||||
import Hyperswarm from 'hyperswarm'
|
import Hyperswarm from 'hyperswarm'
|
||||||
import Hypercore from 'hypercore'
|
import Hypercore from 'hypercore'
|
||||||
import b4a from 'b4a'
|
import b4a from 'b4a'
|
||||||
@@ -35,14 +37,14 @@ import b4a from 'b4a'
|
|||||||
const swarm = new Hyperswarm()
|
const swarm = new Hyperswarm()
|
||||||
Pear.teardown(() => swarm.destroy())
|
Pear.teardown(() => swarm.destroy())
|
||||||
|
|
||||||
const core = new Hypercore(Pear.config.storage)
|
const core = new Hypercore(path.join(Pear.config.storage, 'writer-storage'))
|
||||||
|
|
||||||
// core.key and core.discoveryKey will only be set after core.ready resolves
|
// core.key and core.discoveryKey will only be set after core.ready resolves
|
||||||
await core.ready()
|
await core.ready()
|
||||||
console.log('hypercore key:', b4a.toString(core.key, 'hex'))
|
console.log('hypercore key:', b4a.toString(core.key, 'hex'))
|
||||||
|
|
||||||
// Append all stdin data as separate blocks to the core
|
// Append all stdin data as separate blocks to the core
|
||||||
Pear.stdio.in.on('data', (data) => core.append(data))
|
process.stdin.on('data', (data) => core.append(data))
|
||||||
|
|
||||||
// core.discoveryKey is *not* a read capability for the core
|
// core.discoveryKey is *not* a read capability for the core
|
||||||
// It's only used to discover other peers who *might* have the core
|
// It's only used to discover other peers who *might* have the core
|
||||||
@@ -59,20 +61,21 @@ Create the `reader-app` project with these commands:
|
|||||||
mkdir reader-app
|
mkdir reader-app
|
||||||
cd reader-app
|
cd reader-app
|
||||||
pear init -y -t terminal
|
pear init -y -t terminal
|
||||||
npm install hypercore hyperswarm
|
npm install bare-path hypercore hyperswarm
|
||||||
```
|
```
|
||||||
|
|
||||||
Alter the generated `reader-app/index.js` file to the following:
|
Alter the generated `reader-app/index.js` file to the following:
|
||||||
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
import path from 'bare-path'
|
||||||
import Hyperswarm from 'hyperswarm'
|
import Hyperswarm from 'hyperswarm'
|
||||||
import Hypercore from 'hypercore'
|
import Hypercore from 'hypercore'
|
||||||
|
|
||||||
const swarm = new Hyperswarm()
|
const swarm = new Hyperswarm()
|
||||||
Pear.teardown(() => swarm.destroy())
|
Pear.teardown(() => swarm.destroy())
|
||||||
|
|
||||||
const core = new Hypercore(Pear.config.storage, process.argv[2])
|
const core = new Hypercore(path.join(Pear.config.storage, 'reader-storage'), Pear.config.args[0])
|
||||||
await core.ready()
|
await core.ready()
|
||||||
|
|
||||||
const foundPeers = core.findingPeers()
|
const foundPeers = core.findingPeers()
|
||||||
|
|||||||
Reference in New Issue
Block a user