mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-24 22:52:35 +00:00
docs(readme): update it to reference pull-streams
This commit is contained in:
parent
cc3130fa23
commit
99d07adfac
20
README.md
20
README.md
@ -32,7 +32,7 @@ Include this badge in your readme if you make a new module that uses interface-s
|
|||||||
|
|
||||||
### Node.js
|
### Node.js
|
||||||
|
|
||||||
Install `interface-stream-muxer` as one of the dependencies of your project and as a test file. Then, using `mocha` (for Node.js) or a test runner with compatible API, do:
|
Install `interface-stream-muxer` as one of the dependencies of your project and as a test file. Then, using `mocha` (for JavaScript) or a test runner with compatible API, do:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const test = require('interface-stream-muxer')
|
const test = require('interface-stream-muxer')
|
||||||
@ -58,12 +58,12 @@ test(common)
|
|||||||
|
|
||||||
A valid (read: that follows this abstraction) stream muxer, must implement the following API.
|
A valid (read: that follows this abstraction) stream muxer, must implement the following API.
|
||||||
|
|
||||||
### Attach muxer to a transport
|
### Attach muxer to a Connection
|
||||||
|
|
||||||
- `Node.js` muxedConn = muxer(transport, isListener)
|
- `JavaScript` muxedConn = muxer(conn, isListener)
|
||||||
- `Go` muxedConn, err := muxer.Attach(transport, isListener)
|
- `Go` muxedConn, err := muxer.Attach(conn, isListener)
|
||||||
|
|
||||||
This method attaches our stream muxer to the desired transport (UDP, TCP) and returns/callbacks with the `err, conn`(error, connection).
|
This method attaches our stream muxer to an instance of [Connection](https://github.com/libp2p/interface-connection/blob/master/src/connection.js) defined by [interface-connection](https://github.com/libp2p/interface-connection).
|
||||||
|
|
||||||
If `err` is passed, no operation should be made in `conn`.
|
If `err` is passed, no operation should be made in `conn`.
|
||||||
|
|
||||||
@ -74,22 +74,22 @@ If `err` is passed, no operation should be made in `conn`.
|
|||||||
### Dial(open/create) a new stream
|
### Dial(open/create) a new stream
|
||||||
|
|
||||||
|
|
||||||
- `Node.js` stream = muxedConn.newStream([function (err, stream)])
|
- `JavaScript` stream = muxedConn.newStream([function (err, stream)])
|
||||||
- `Go` stream, err := muxedConn.newStream()
|
- `Go` stream, err := muxedConn.newStream()
|
||||||
|
|
||||||
This method negotiates and opens a new stream with the other endpoint.
|
This method negotiates and opens a new stream with the other endpoint.
|
||||||
|
|
||||||
If `err` is passed, no operation should be made in `stream`.
|
If `err` is passed, no operation should be made in `stream`.
|
||||||
|
|
||||||
`stream` interface our established Stream with the other endpoint, it must implement the [Duplex Stream interface](https://nodejs.org/api/stream.html#stream_class_stream_duplex) in Node.js or the [ReadWriteCloser](http://golang.org/pkg/io/#ReadWriteCloser) in Go.
|
`stream` interface our established Stream with the other endpoint, it must implement the [Duplex pull-stream interface](https://pull-stream.github.io) in JavaScript or the [ReadWriteCloser](http://golang.org/pkg/io/#ReadWriteCloser) in Go.
|
||||||
|
|
||||||
In the Node.js case, if no callback is passed, stream will emit an 'ready' event when it is prepared or a 'error' event if it fails to establish the connection, until then, it will buffer the 'write' calls.
|
In the JavaScript case, if no callback is passed, stream will emit an 'ready' event when it is prepared or a 'error' event if it fails to establish the connection, until then, it will buffer the 'write' calls.
|
||||||
|
|
||||||
### Listen(wait/accept) a new incoming stream
|
### Listen(wait/accept) a new incoming stream
|
||||||
|
|
||||||
- `Node.js` muxedConn.on('stream', function (stream) {})
|
- `JavaScript` muxedConn.on('stream', function (stream) {})
|
||||||
- `Go` stream := muxedConn.Accept()
|
- `Go` stream := muxedConn.Accept()
|
||||||
|
|
||||||
Each time a dialing peer initiates the new stream handshake, a new stream is created on the listening side.
|
Each time a dialing peer initiates the new stream handshake, a new stream is created on the listening side.
|
||||||
|
|
||||||
In Node.js, the Event Emitter pattern is expected to be used in order to receive new incoming streams, while in Go, it expects to wait when Accept is called.
|
In JavaScript, the Event Emitter pattern is expected to be used in order to receive new incoming streams, while in Go, it expects to wait when Accept is called.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"name": "interface-stream-muxer",
|
"name": "interface-stream-muxer",
|
||||||
"version": "0.3.1",
|
"version": "0.3.1",
|
||||||
"description": "A test suite and interface you can use to implement a stream muxer.",
|
"description": "A test suite and interface you can use to implement a stream muxer.",
|
||||||
"main": "src/index.js",
|
"main": "lib/index.js",
|
||||||
"jsnext:main": "src/index.js",
|
"jsnext:main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "exit(0)",
|
"test": "exit(0)",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user