# trooba-streaming

> nodejs streaming wrappers/helper for trooba pipeline

Latest version **0.1.0** (published 2017-01-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install trooba-streaming
pnpm add trooba-streaming
yarn add trooba-streaming
bun add trooba-streaming
```

## 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.0 |
| Published | 2017-01-05 |
| First published | 2017-01-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dmytro Semenov |
| Maintainers | dimichgh |
| Keywords | trooba, pipeline, service, grpc, http, streaming, stream, writable, readable |

## Links

- npm: https://www.npmjs.com/package/trooba-streaming
- npm.io page: https://npm.io/package/trooba-streaming

## 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.1.0 (latest) — 2017-01-05

## README

# trooba-streaming

[![codecov](https://codecov.io/gh/trooba/trooba-streaming/branch/master/graph/badge.svg)](https://codecov.io/gh/trooba/trooba-streaming)
[![Build Status](https://travis-ci.org/trooba/trooba-streaming.svg?branch=master)](https://travis-ci.org/trooba/trooba-streaming) [![NPM](https://img.shields.io/npm/v/trooba-streaming.svg)](https://www.npmjs.com/package/trooba-streaming)
[![Downloads](https://img.shields.io/npm/dm/trooba-streaming.svg)](http://npm-stat.com/charts.html?package=trooba-streaming)
[![Known Vulnerabilities](https://snyk.io/test/github/trooba/trooba-streaming/badge.svg)](https://snyk.io/test/github/trooba/trooba-streaming)

[Trooba](https://github.com/trooba/trooba) framework being isomorphic does not use nodejs native streaming.

This module provides nodejs streaming API for trooba pipeline.

## Get Involved

- **Contributing**: Pull requests are welcome!
    - Read [`CONTRIBUTING.md`](.github/CONTRIBUTING.md) and check out our [bite-sized](https://github.com/trooba/trooba-streaming/issues?q=is%3Aissue+is%3Aopen+label%3Adifficulty%3Abite-sized) and [help-wanted](https://github.com/trooba/trooba-streaming/issues?q=is%3Aissue+is%3Aopen+label%3Astatus%3Ahelp-wanted) issues
    - Submit github issues for any feature enhancements, bugs or documentation problems
- **Support**: Join our [gitter chat](https://gitter.im/trooba) to ask questions to get support from the maintainers and other Trooba developers
    - Questions/comments can also be posted as [github issues](https://github.com/trooba/trooba-streaming/issues)

## Install

```bash
npm install trooba-streaming --save
```

## Usage

### request/stream use-case
```js
var Trooba = require('trooba');

var pipe = new Trooba();
pipe.use(function echo(pipe) {
    var _request;
    var streamResponse;
    pipe.on('request', request => {
        _request = request;
        streamResponse = new TroobaWritableStream(pipe.streamResponse({
            statusCode: 200
        }));
    });
    pipe.on('request:data', data => {
        _request.forEach(data => {
            streamResponse.write(data);
        });
        streamResponse.end();
    });
})
.build();

var stream = new TroobaReadableStream(pipe.create().request(['foo', 'bar']));

stream
.on('response', response => {
    console.log('Response metadata:', response);
})
.on('error', err => {
    console.log('Error:', err);
})
.on('data', data => {
    console.log('Data:', data);
})
.on('end', () => {
    console.log('end of stream');
});
```

### stream/response use-case
```js
var Trooba = require('trooba');

var pipe = new Trooba()
.use(function echo(pipe) {
    pipe.on('request', (request, next) => {
        var response = [];

        new TroobaReadableStream(pipe)
        .on('data', data => {
            response.push(data);
        })
        .on('end', () => {
            pipe.respond(response);
        });

        next();
    });
})
.build();

var request = pipe.create().streamRequest('r1');
var stream = new TroobaWritableStream(request);

stream.on('response', response => {
    console.log('Response:', response);
    done();
});
stream.write('foo');
stream.write('bar');
stream.end();
```

### stream/stream use-case
```js
var Trooba = require('trooba');

var pipe = new Trooba()
.use(function echo(pipe) {
    pipe.on('request', (request, next) => {
        var stream = new TroobaDuplexStream(pipe.streamResponse(request))
        .on('data', data => {
            stream.write(data);
        })
        .on('end', () => {
            stream.end();
        });

        next();
    });
})
.build();

var order = [];

var stream = new TroobaWritableStream(pipe.create().streamRequest('r1'));

stream
.on('error', done)
.on('response:data', data => {
    if (data) {
        order.push(data);
        return;
    }
    console.log('Data received:', order);
    done();
});

stream.write('foo');
stream.write('bar');
stream.end();
```

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