2.6.5 • Published 3 years ago

streamcat v2.6.5

Weekly downloads
99
License
MIT
Repository
-
Last release
3 years ago

streamcat

Concatenate Node JS Streams!

You can concatenate the result of Promises, non async buffers and other streams allowing you to sequence things into an asynchronous Stream.

Usage

Example, print the contents of myfileA followed by myfileB, this is equivalent to using cat(1): cat myfileA myfileB.

var streamCat = require('streamcat');

streamCat([
	fs.createReadStream('myfileA'),
	fs.createReadStream('myfileB')
]).pipe(process.stdout);

API

streamCat(listOfStreamsBuffersOrPromises)

streamCat will take a list of ReadStreams, Buffers, or Promises returning a ReadStream or Buffer as its only argument and returns a ReadStream that will stream the concatenation of each item in the list.

You can mix Buffer, ReadStream, and Promise usage, in this instance, the String "Some content" will be streamed between myfileA and myfileB:

streamCat([
	fs.createReadStream('myfileA'),
	new Buffer("Some content"),
	fs.createReadStream('myfileB')
]).pipe(process.stdout);

Example using Promises that has the same result as the above example, the value in the Promise is resolved asynchronously:

streamCat([
	fs.createReadStream('myfileA'),
	Promise.resolve(new Buffer("Some content")),
	fs.createReadStream('myfileB')
]).pipe(process.stdout);

Error Handling

The streamCat function can take an optional options object as its second argument.

errorMapper

The errorMapper option allows you to specify a function that can transform an error from any of the contatenated streams before emitting the error on the returned stream.

The errorMapper must return an error object.

{
	errorMapper: function(error) {
		error.message = error.message + ": my custom context";
		return error;
	}
}

License

MIT

2.6.5

3 years ago

2.6.4

4 years ago

2.6.0

9 years ago

2.5.0

9 years ago

2.4.1

9 years ago

2.4.0

9 years ago

2.3.1

9 years ago

2.3.0

9 years ago

2.2.3

9 years ago

2.2.2

9 years ago

2.2.1

9 years ago

2.2.0

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago