# movable-stream

> Move a stream between underlying streams, transparently

Latest version **0.0.1** (published 2018-01-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install movable-stream
pnpm add movable-stream
yarn add movable-stream
bun add movable-stream
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2018-01-14 |
| First published | 2018-01-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | John Hiesey |
| Maintainers | jhiesey |
| Keywords | stream, movable, switchable |

## Links

- npm: https://www.npmjs.com/package/movable-stream
- Repository: https://github.com/jhiesey/movable-stream
- Homepage: https://github.com/jhiesey/movable-stream#readme
- Issues: https://github.com/jhiesey/movable-stream/issues
- npm.io page: https://npm.io/package/movable-stream

## Dependencies (4)

- [pump](https://npm.io/package/pump.md) ^2.0.0
- [inherits](https://npm.io/package/inherits.md) ^2.0.1
- [through2](https://npm.io/package/through2.md) ^2.0.0
- [duplexify](https://npm.io/package/duplexify.md) ^3.4.2

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2018-01-14

## README

# movable-stream

## What?

This module is a duplex stream, like a regular socket, which wraps some, other *underlying* duplex stream. You use one instance to wrap each end of the underlying stream, and it allows you to *replace* the underlying stream, while data is flowing, without the code using the movable stream noticing that anything changed.

It switches streams... midstream.

## Why?

Say you want to send data between two browsers using WebRTC data channels. You already need to connect to a signaling server (using e.g. websockets) to open a WebRTC connection in the first place, and it takes a little while for the WebRTC connection to open.

Instead of waiting for the connection to open before sending data, you can set up a stream multiplexed on top of the websockets you already have that forwards data from browser <-> server <-> browser. You are using the server, temporarily, as a relay. Once the WebRTC connection is open, you can transparently replace the relayed connection with the brand-new WebRTC connection, all without the code using the stream noticing anything changed at all!

## Example

``` js
let Movable = require('movable-stream')

let originalStream = ... // whatever stream you want wrap initially (e.g. over websockets)

let ms = new Movable(originalStream)

// now ms is readable and writable
ms.on('data', (chunk) => {
  console.log('Received ${chunk.length} bytes of data.');
});

ms.write('hello, world!')

let newStream = ... // a replacement for originalStream (e.g. WebRTC data channel stream)

ms.on('moved', () => {
	originalStream.destroy() // original stream is no longer needed
})
ms.replace(newStream) // data starts flowing over newStream instead of originalStream, transparently

```

## License

MIT

---
_Source: https://npm.io/package/movable-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
