# socket.io-pull-stream

> Pull Streams for socket.io

Latest version **0.1.5** (published 2018-03-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install socket.io-pull-stream
pnpm add socket.io-pull-stream
yarn add socket.io-pull-stream
bun add socket.io-pull-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.1.5 |
| Published | 2018-03-07 |
| First published | 2017-09-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 14.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Maciej Krüger |
| Maintainers | mkg20001 |
| Keywords | pull-stream, socket.io, stream |

## Links

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

## Dependencies (4)

- [uuid](https://npm.io/package/uuid.md) ^3.2.1
- [debug](https://npm.io/package/debug.md) ^3.1.0
- [data-queue](https://npm.io/package/data-queue.md) 0.0.3
- [pull-stream](https://npm.io/package/pull-stream.md) ^3.6.2

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.5 (latest) — 2018-03-07
- 0.1.4 — 2018-01-31
- 0.1.3 — 2017-12-06
- 0.1.2 — 2017-12-06
- 0.1.1 — 2017-09-06
- 0.1.0 — 2017-09-02
- 0.0.1 — 2017-09-02

## README

# socket.io-pull-stream

Pull Streams for socket.io

# API

-   `sp(io[, opt])`

    Will add the functions below to `io`

    -   `io`: Socket.io-client instance

    -   `opt`: Default options for every stream

-   `.createSink([id, opt])`

    Will create a sink with `id`.
    If no id is provided a new id will be generated and can be found under `sink.id`

    -   `opt`: Object. Config for stream

        -   `codec`: Codec to use.

            Either string (`hex, plain, buffer`) or object (`{encode: data => ..., decode: data => ...}`).

            Default: `plain`

    Returns: Sink Function

-   `.createSource(id[, opt])`

    Will create a source that reads from a sink with id `id` on the other side.

    -   `opt`: Object. Config for stream

        -   `codec`: Codec to use.

            Either string (`hex, plain, buffer`) or object (`{encode: data => ..., decode: data => ...}`).

            Default: `plain`

    Returns: Source Function

-   `.createProxy(id, to)`

    Will proxy the stream `id` to socket `to`

# Examples

## File Stream

Server:

```js
const sp = require('socket.io-pull-stream')
const fs = require('fs')
const toPull = require('stream-to-pull-stream')
const pull = require('pull-stream')

io.on('connection', client => {
  sp(client)
  const ws = toPull.source(fs.createReadStream('some_file.txt'))
  const sink = client.createSink()
  client.emit('file', sink.id) // to send the stream just emit the id (IMPORTANT: EMIT THE ID FIRST, LATER CREATE THE SOURCE IN SYNC)
  pull(
    ws,
    sink
  )
})
```

Client:

```js
const sp = require('socket.io-pull-stream')
const pull = require('pull-stream')

sp(io)

io.on('file', id => {
  pull(
    io.createSource(id), // to recieve just create a source with the id (IMPORTANT: DO THAT SYNC)
    pull.collect((err, data) => {
      if (err) throw err
      console.log(Buffer.from(data).toString()) // our data
    })
  )
})
```

To send streams between clients the stream need to be proxied

```js
// TODO :add
```

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