$ cnpm install sandwich-stream
While I'm not overjoyed about how performant the internals will operate, I wanted a readable stream that was ACTUALLY A READABLE STREAM. Not a streams1 stream masquerading as streams2. As soon as somebody writes a better concat stream as a readable stream with a nice simple API, this baby is going to develop some serious abandonment issues.
npm install sandwich-stream --save
note: this code was made using it TypeScript, and its typings are linked in package.json, so there's no need of installing @types/sandwich-stream or anything related.
import { SandwichStream } from 'sandwich-stream';
// OR EVEN:
// const SandwichStream = require('sandwich-stream');
const sandwich = SandwichStream({
head: 'Thing at the top\n',
tail: '\nThing at the bottom',
separator: '\n ---- \n'
});
sandwich.add(aStreamIPreparedEarlier)
.add(anotherStreamIPreparedEarlier)
.add(aFurtherStreamIPreparedEarlier)
.pipe(process.stdout);
// The thing at the top
// ----
// Stream1
// ----
// Stream2
// ----
// Stream3
// The thing at the bottom
head option takes a string/buffer and pushes the string before all other contentfoot option takes a string/buffer and pushes the string after all other data has been pushedseparator option pushes a string/buffer between each streamToo add a stream use the .add method: sandwich.add(streamVariable);
Wanna known more about Node Streams? Read this.
Copyright 2013 - present © cnpmjs.org | Home |