Skip to content
JavaScript implementation of multistream-select
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
src chore: add errcode for multicodec not supported (#49) Jul 9, 2019
test chore: add errcode for multicodec not supported (#49) Jul 9, 2019
.gitignore chore Oct 23, 2017
.npmignore docs(api): first pass Dec 14, 2016
.travis.yml chore: use travis for ci (#50) Jul 9, 2019 chore: release version v0.14.6 Jul 23, 2019
LICENSE Initial commit Jun 7, 2015 docs: fix typo in readme Oct 15, 2018
example.js chore: use travis for ci (#50) Jul 9, 2019


Coverage Status Travis CI Circle CI Dependency Status js-standard-style

JavaScript implementation of multistream-select.

Lead Maintainer

Jacob Heun

Table of Contents


What is multistream-select

tl;dr: multistream-select is protocol multiplexing per connection/stream. Full spec here

Select a protocol flow

The caller will send "interactive" messages, expecting for some acknowledgement from the callee, which will "select" the handler for the desired and supported protocol

< /multistream-select/0.3.0  # i speak multistream-select/0.3.0
> /multistream-select/0.3.0  # ok, let's speak multistream-select/0.3.0
> /ipfs-dht/0.2.3            # i want to speak ipfs-dht/0.2.3
< na                         # ipfs-dht/0.2.3 is not available
> /ipfs-dht/0.1.9            # What about ipfs-dht/0.1.9 ?
< /ipfs-dht/0.1.9            # ok let's speak ipfs-dht/0.1.9 -- in a sense acts as an ACK
> <dht-message>
> <dht-message>
> <dht-message>

This mode also packs a ls option, so that the callee can list the protocols it currently supports



> npm i multistream-select



const multistream = require('multistream-select')

Browser: Browserify, Webpack, other bundlers

The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.

const multistream = require('multistream-select')

Browser: <script> Tag

Loading this module through a script tag will make the MultistreamSelect obj available in the global namespace.

<script src=""></script>
<!-- OR -->
<script src=""></script>


Attach multistream to a connection (socket)

const multistream = require('multistream-select')

const ms = new multistream.Listener()
// or
const ms = new multistream.Dialer()

// apply the multistream to the conn
ms.handle(conn, callback)

This module uses pull-streams

We expose a streaming interface based on pull-streams, rather than on the Node.js core streams implementation (aka Node.js streams). pull-streams offers us a better mechanism for error handling and flow control guarantees. If you would like to know more about why we did this, see the discussion at this issue.

You can learn more about pull-streams at:

Converting pull-streams to Node.js Streams

If you are a Node.js streams user, you can convert a pull-stream to a Node.js stream using the module pull-stream-to-stream, giving you an instance of a Node.js stream that is linked to the pull-stream. For example:

const pullToStream = require('pull-stream-to-stream')

const nodeStreamInstance = pullToStream(pullStreamInstance)
// nodeStreamInstance is an instance of a Node.js Stream

To learn more about this utility, visit



Captain: @diasdavid.


Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.


MIT © 2015 David Dias

You can’t perform that action at this time.