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

rxjs-stream

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rxjs-stream

nodejs streams for rxjs 6

  • 3.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.8K
increased by2.08%
Maintainers
1
Weekly downloads
 
Created
Source

rxjs-stream

This is a simple library for converting to and from NodeJS stream and rxjs 6.

This was created to fill the gap left by rx-node, which only works with rxjs 4.

Installation

npm install --save rxjs rxjs-stream

Usage

Writing to a stream.

import {rxToStream} from 'rxjs-stream';

let data = 'This is a bit of text to have some fun with';
let src = Rx.Observable.from(data.split(' '));
rxToStream(src).pipe(process.stdout);

Writing objects to a stream

To write objects, you must pass in the ReadableOptions with objectMode to be true: { objectMode: true }

import {rxToStream} from 'rxjs-stream';

let data = 'This is a bit of text to have some fun with';
let wordObj = data.split(' ').map(text => ({ text }));
let src = Rx.Observable.from(wordObj);
let stream = rxToStream(src, { objectMode: true });

Read from a stream

import {rxToStream, streamToStringRx} from 'rxjs-stream';

// Read stdin and make it upper case then send it to stdout
let ob = streamToStringRx(process.stdin)
    .map(text => text.toUpperCase());

rxToStream(ob).pipe(process.stdout);

Performance

It is recommended to buffer observable values before sending them to the stream. Node streams work better with fewer calls of a large amount of data than with many calls with a small amount of data.

Example:

import * as loremIpsum from 'lorem-ipsum';
import {rxToStream} from 'rxjs-stream';

let book = loremIpsum({ count: 1000, format: 'plain', units: 'paragraphs'});
let words = Rx.Observable.from(book.split(/\b/));
let wordsBuffered = words.bufferCount(1000).map(words => words.join(''));
let stream = rxToStream(wordsBuffered);

stream.pipe(process.stdout);

Compatibility

This library is tested with Node 10 and above.

Keywords

FAQs

Package last updated on 18 Jul 2021

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