next-stream
Concatenate a series of streams 'end-to-end'.
Last updated 6 years ago by anandthakker .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install next-stream 
SYNC missed versions from official npm registry.

next-stream Build Status

Concatenate/attach a series of streams a,b,c,... "end-to-end", so that the result streams from a until it ends, then moves on to b till it ends, etc.

If you don't need mutation, laziness, or non-streams, you should probably just use stream-cat.

Supports:

  • (limited) mutation: Append additional streams after creation with push(stream).
  • laziness: If anything in the series is a function instead of a stream, it will be called when its 'turn' comes up, and its return value will be used in its place.
  • non-stream items: If anything in the series is not a readable stream just push it through as a chunk at the appropriate time.
  • stream errors: If any of the given streams in the series emits an error, propagate it.

Usage

var next = require('next-stream');

var stream1 = fs.createReadStream('file1.txt'),
    stream2 = fs.createReadStream('file2.txt'),
    joined = next([stream1, stream2]);

joined.push(fs.createReadStream('file3.txt'));
joined.close(); // tell `joined` to emit `end` when the last stream ends.

joined.pipe(process.stdout);

Outputs contents of file1.txt followed by contents of file2.txt and then the contents of file3.txt.

For convenience, non-stream inputs also work as you'd expect:

var next = require('next-stream');

var stream1 = fs.createReadStream('file1.txt'),
stream2 = fs.createReadStream('file2.txt'),
joined = next([stream1, '--------- between ---------', stream2]);

joined.pipe(process.stdout);

Outputs contents of file1.txt, followed by '--------- between ---------', followed by contents of file2.txt.

Methods

var joined = next([stream1, stream2, stream3], opts);

Create a new readable next-stream from the readable streams stream1, stream2, stream3.

By default, joined is in open-ended mode, which means it won't emit 'end' when the last stream in the list ends. Setting opts.open to false causes joined to end when the last stream ends.

joined.push(stream4)

Add stream4 to the end of the list of streams.

joined.close()

Close joined if it is in open-ended mode.

Events

'next'

Emitted when we've hit the end event of the current stream. Event payload is the next stream, or null if there are none.

Current Tags

  • 2.2.2                                ...           latest (6 years ago)

12 Versions

  • 2.2.2                                ...           6 years ago
  • 2.2.1                                ...           6 years ago
  • 2.2.0                                ...           6 years ago
  • 2.1.2                                ...           6 years ago
  • 2.1.1                                ...           6 years ago
  • 2.1.0                                ...           6 years ago
  • 2.0.3                                ...           6 years ago
  • 2.0.2                                ...           6 years ago
  • 2.0.1                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (3)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |