<commit_before>multiplex-stream-muxer Node.js Implementation
=============================================

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)

> Abstraction on top of multiplex, implementing the abstract-stream-muxer interface

[![](https://github.com/diasdavid/abstract-stream-muxer/blob/master/img/badge.png)](https://github.com/diasdavid/abstract-stream-muxer)

# Usage

multiplex-stream-muxer follows the [abstract-stream-muxer API](https://github.com/diasdavid/abstract-stream-muxer#api)

# Example

```JavaScript
// Client.js
var MultiplexStreamMuxer = require('multiplex-stream-muxer')

var dialer = new MultiplexStreamMuxer()

var connDialer = dialer.attach(pair, false)

connDialer.dialStream(function (err, stream) {
  t.ifError(err, 'Should not throw')
  t.pass('dialed stream')
})
```

```JavaScript
// Server.js
var MultiplexStreamMuxer = require('multiplex-stream-muxer')

var listener = new MultiplexStreamMuxer()

var connListener = listener.attach(pair.other, true)

connListener.on('stream', function (stream) {
  t.pass('got stream')
})
```<commit_msg>update readme with net.connect pattern example<commit_after>multiplex-stream-muxer Node.js Implementation
=============================================

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)

> Abstraction on top of multiplex, implementing the abstract-stream-muxer interface

[![](https://github.com/diasdavid/abstract-stream-muxer/blob/master/img/badge.png)](https://github.com/diasdavid/abstract-stream-muxer)

# Usage

multiplex-stream-muxer follows the [abstract-stream-muxer API](https://github.com/diasdavid/abstract-stream-muxer#api)

# Example

```JavaScript
// Client.js
var MultiplexStreamMuxer = require('multiplex-stream-muxer')

var dialer = new MultiplexStreamMuxer()

var connDialer = dialer.attach(socket, false)

connDialer.dialStream(function (err, stream) {
  t.ifError(err, 'Should not throw')
  t.pass('dialed stream')
})
```

```JavaScript
// Server.js
var MultiplexStreamMuxer = require('multiplex-stream-muxer')

var listener = new MultiplexStreamMuxer()

var connListener = listener.attach(socket, true)

connListener.on('stream', function (stream) {
  t.pass('got stream')
})
```

You can also follow the net.connect pattern by listening to the `ready` and `error` events

```JavaScript
var stream = connListener.dialStream()

stream.on('ready', function () {})

stream.on('error', function (err) {})

stream.write('buffer this') // this write will be buffered untill the socket is ready to transmit
```
{'fraction_non_alphanumeric': 0.1854029747492217, 'fraction_numerical': 0.005534417156693186, 'mean_word_length': 5.8530805687203795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '695871', 'n_tokens_mistral': 1008, 'n_tokens_neox': 938, 'n_words': 167}