Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

streamqueue

nfroidure268.6kMIT2.0.0TypeScript support: included

StreamQueue pipe the queued streams one by one in order to preserve their content order.

queue, streaming, stream, async, pipe

readme

streamqueue

StreamQueue pipe the queued streams one by one in order to preserve their content order.

GitHub license

Usage

Install the npm module:

npm install streamqueue --save

Then, in your scripts:

import { StreamQueue } from 'streamqueue';
import { createReadStream } from 'node:fs';

const queue = new StreamQueue(
  createReadStream('input.txt'),
  createReadStream('input2.txt'),
  createReadStream('input3.txt'),
).pipe(process.stdout);

StreamQueue also accept functions returning streams, the above can be written like this, doing system calls only when piping:

import { queueStreams } = require('streamqueue');
import { createReadStream } from 'node:fs';

const queue = queueStreams(
  createReadStream.bind(null, 'input.txt'),
  createReadStream.bind(null, 'input2.txt'),
  createReadStream.bind(null, 'input3.txt'),
).pipe(process.stdout);

Object-oriented traditionnal API offers more flexibility:

import { StreamQueue } from 'streamqueue';
import { createReadStream } from 'node:fs';

const queue = new StreamQueue();

queue.queue(
  createReadStream('input.txt'),
  createReadStream('input2.txt'),
  createReadStream('input3.txt'),
);
queue.done();

queue.pipe(process.stdout);

You can also chain StreamQueue methods like that:

import StreamQueue from 'streamqueue';
import { createReadStream } from 'node:fs';

new StreamQueue()
  .queue(createReadStream('input.txt'))
  .queue(createReadStream('input2.txt'))
  .queue(createReadStream('input3.txt'))
  .done()
  .pipe(process.stdout);

You can queue new streams at any moment until you call the done() method. So the created stream will not fire the end event until done() call.

Stats

NPM NPM

Contributing

Feel free to propose your code if you agree with publishing it under the MIT license.

API

Classes

StreamQueue

Pipe queued streams sequentially

Functions

queueObjectStreams(options, ...streams)

Create a new queue in object mode and pipe given streams and end if some

queueStreams(options, ...streams)

Create a new queue and pipe given streams and end if some

StreamQueue

Pipe queued streams sequentially

Kind: global class

new StreamQueue(options, ...streams)

Create a new queue and pipe given streams and end if some

Returns: StreamQueue

Param Type Description
options Object The queue options
options.objectMode boolean Operate in object mode
options.pauseFlowingStream boolean Pause given streams that are flowing
options.resumeFlowingStream boolean Resume given streams that are flowing
...streams Readable | function The stream or stream returning function to pipe in

streamQueue.queue(...streams) ⇒

Queue each stream given in argument

Kind: instance method of StreamQueue
Returns: StreamQueue

Param Type Description
...streams Readable | function The stream or stream returning function to pipe in

streamQueue.done(...streams) ⇒

Queue each stream given in argument and end

Kind: instance method of StreamQueue
Returns: StreamQueue

Param Type Description
...streams Readable | function The stream or stream returning function to pipe in

queueObjectStreams(options, ...streams) ⇒

Create a new queue in object mode and pipe given streams and end if some

Kind: global function
Returns: StreamQueue

Param Type Description
options Object The queue options
...streams Readable | function The stream or stream returning function to pipe in

queueStreams(options, ...streams) ⇒

Create a new queue and pipe given streams and end if some

Kind: global function
Returns: StreamQueue

Param Type Description
options Object The queue options
...streams Readable | function The stream or stream returning function to pipe in

Authors

License

MIT

changelog

2.0.0 (2024-07-18)

Bug Fixes

  • docs: fix markdown title (984bdee)

Code Refactoring

  • core: complete refactoring (a969877)

BREAKING CHANGES

  • core: Support only Node20+, use ESM, API surface changed. By updating assume you could have a lot of work to do.

1.1.2 (2017-12-03)

build

  • metapak-nfroidure: Add metapak-nfroidure (a8a9572)

BREAKING CHANGES

  • metapak-nfroidure: Remove support for Node version prior to the last LTS

v1.1.1 (2015/08/27 11:33 +00:00)

  • a772c39 1.1.1 (@nfroidure)
  • a2443fd Fixing the .obj() shortcut with no args fix #9 (@nfroidure)

v1.1.0 (2015/06/09 06:19 +00:00)

  • f8f8fc3 1.1.0 (@nfroidure)
  • 403331d Adding a .obj method (@nfroidure)

v1.0.0 (2015/06/08 16:41 +00:00)

  • 1d1399e 1.0.0 (@nfroidure)
  • acf36b7 Updating dependencies (@nfroidure)
  • 7473d22 Fixing hints (@nfroidure)
  • cc0b79b Fix travis build (@nfroidure)

v0.1.3 (2015/02/14 14:40 +00:00)

v0.1.2 (2015/02/14 14:36 +00:00)

  • af60e80 Removing uneccessary deps (@nfroidure)
  • b43bcd0 Using streamtest for tests (@nfroidure)
  • ca0e386 Inherit of Readable instead of PassThrough (@nfroidure)
  • 47ec014 Reverting setImmadiate for node 0.8 (@nfroidure)
  • 9b6be4a Isolation state prop in a single object (@nfroidure)
  • 962ec36 Increasing the streamqueue version (@nfroidure)
  • 9bde919 Fixing the regression closes #5 (@nfroidure)
  • 00f5d8c Replacing setTimmediate per setTimeout in tests to match Node 0.8 (@nfroidure)
  • 5e1d91d Trying to change the ^ per ~ to fix the Node 0.8 build (@nfroidure)
  • cc7858b Remove legacy streams wrappers since using readable-stream (@nfroidure)
  • 9aac64e Conflicts: src/index.js (@nfroidure)
  • e85916e Remove require of platform streams (@nfroidure)
  • 82b81fe Using isstream instead of custom function isaacs/readable-stream#87 (@nfroidure)
  • 9e92377 Updating dependencies (@nfroidure)
  • a2324c8 Fireing end asynchronously for consistencies with node streams #4 (@nfroidure)
  • bb27bb8 Testing streamqueues inside streamqueues #4 (@nfroidure)
  • 92106fc Execute end instead of firing the event (@nfroidure)
  • 1f1a917 Making .done() fire "end" asynchronously (@fidian)
  • 40bfb72 Version update (@nfroidure)
  • 21e2eee iImproving performances by unpiping previously piped stream (@nfroidure)
  • 0a13b08 Fixing the README file (@nfroidure)
  • 18b2347 New version 0.0.6 (@nfroidure)
  • f75dc68 Added badges (@nfroidure)
  • 421923a Dependencies update (@nfroidure)
  • c79479a Depending on readable stream closes #3 (@nfroidure)
  • 46b3e5f Accepting fucntion returning streams (@nfroidure)
  • a355962 Ginving up 0.11. Waiting 0.12 (@nfroidure)
  • 29a15f2 Fix attempt for node 0.11 (@nfroidure)
  • 973c094 Improved code coverage (@nfroidure)
  • c3b0116 Added coverage tests (@nfroidure)
  • ecfdcc4 New verion 0.0.4 (@nfroidure)
  • 8d4a0f6 Fix for objectMode old streams (@nfroidure)
  • 88f2e13 Wrap old streams automatically (@nfroidure)
  • b58e827 Deprecating pause option, pausing/resuming flowing mode streams automtically (@nfroidure)
  • a5a7241 Added support for flowing mode, pause not aware streams (@nfroidure)
  • 0d71911 Going to 0.0.2 (@nfroidure)
  • d7adcdd Merging master (@nfroidure)
  • 86bd513 Adding functionnal API + pause option (@nfroidure)
  • #2 Make new keyword optional (@darsain)
  • 9d18b32 Make new keyword optional (@darsain)
  • 4b0f385 Fix the NPM module link (@nfroidure)
  • e5a4ecd Reemitting errors (@nfroidure)
  • 91c874e Replacing end by done (@nfroidure)
  • b578cf2 Improved the readme + added the cli tests command (@nfroidure)
  • 3b4d9cd First commit (@nfroidure)