Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

trooba-streaming

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trooba-streaming

nodejs streaming wrappers/helper for trooba pipeline

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

trooba-streaming

codecov Build Status NPM Downloads Known Vulnerabilities

Trooba framework being isomorphic does not use nodejs native streaming.

This module provides nodejs streaming API for trooba pipeline.

Get Involved

Install

npm install trooba-streaming --save

Usage

request/stream use-case

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

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

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();

Keywords

FAQs

Package last updated on 05 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc