@ aptre/ yamux
JavaScript 的 Yamux 流多路xer
关于
此模块是 JavaScript 执行 哈希公司的亚穆克 用于尽可能少的依赖.
这是叉子 链安全网的js-libp2p-yamux 并删除了用于独立应用程序的 libp2p 依赖.
示例 - 使用低级API
import { yamux } from '@aptre/yamux'
import { pipe } from 'it-pipe'
import { duplexPair } from 'it-pair/duplex'
import all from 'it-all'
// Connect two yamux muxers to demo basic stream multiplexing functionality
const clientMuxer = yamux({
client: true,
onIncomingStream: stream => {
// echo data on incoming streams
pipe(stream, stream)
},
onStreamEnd: stream => {
// do nothing
}
})()
const serverMuxer = yamux({
client: false,
onIncomingStream: stream => {
// echo data on incoming streams
pipe(stream, stream)
},
onStreamEnd: stream => {
// do nothing
}
})()
// `p` is our "connections", what we use to connect the two sides
// In a real application, a connection is usually to a remote computer
const p = duplexPair()
// connect the muxers together
pipe(p[0], clientMuxer, p[0])
pipe(p[1], serverMuxer, p[1])
// now either side can open streams
const stream0 = clientMuxer.newStream()
const stream1 = serverMuxer.newStream()
// Send some data to the other side
const encoder = new TextEncoder()
const data = [encoder.encode('hello'), encoder.encode('world')]
pipe(data, stream0)
// Receive data back
const result = await pipe(stream0, all)
// close a stream
stream1.close()
// close the muxer
clientMuxer.close()
安装
$ npm i @aptre/yamux
或者说
$ yarn add @aptre/yamux
许可证
根据其中任何一项颁发的许可证
- Apache 2.0, (英语:自由主义 编号 : http://www.apache.org/licenses/LICENSE-2.0 (中文(简体) )(中文(简体) )
- 麻省理工学院利马 编号 : http://opensource.org/licenses/MIT 互联网档案馆的存檔,存档日期2013-12-02(中文(简体) )
捐款
除非另有明确声明,Apache-2.0许可证中界定的、有意提交供列入作品的任何捐助,应具有上述双重许可证,不附加任何条件.