node.js-stream

How to pipe output of a node CLI program to shell?

风流意气都作罢 提交于 2019-12-02 06:24:33
问题 I basically want to do something like this: $ my-node-cli <some-param> | less Note that less is just an example. I need it to work with any other *nix command. More about the use case: I wrote a node CLI package that searches some online resource and outputs results to the shell. Since the result set can be huge, client wants to do additional operations on it, e.g grep , head , tail , tee , ... anything really. I searched far and wide and I only managed to find the way to pipe into node

How to pipe output of a node CLI program to shell?

别等时光非礼了梦想. 提交于 2019-12-01 22:48:45
I basically want to do something like this: $ my-node-cli <some-param> | less Note that less is just an example. I need it to work with any other *nix command. More about the use case: I wrote a node CLI package that searches some online resource and outputs results to the shell. Since the result set can be huge, client wants to do additional operations on it, e.g grep , head , tail , tee , ... anything really. I searched far and wide and I only managed to find the way to pipe into node program, not out of . My current idea is to capture the right side of pipe when my program is called, then,

untarring files to S3 fails, not sure why

一曲冷凌霜 提交于 2019-12-01 00:56:33
(new information below) I am trying to set up a lambda function that reacts to uploaded tgz files by uncompressing them and writing the results back to S3. The unzip and untar work fine, but uploading to S3 fails: /Users/russell/lambda/gzip/node_modules/aws-sdk/lib/s3/managed_upload.js:350 var buf = self.body.read(self.partSize - self.partBuffer.length) || ^ TypeError: undefined is not a function at ManagedUpload.fillStream (/Users/russell/lambda/gzip/node_modules/aws-sdk/lib/s3/managed_upload.js:350:25) at Entry.<anonymous> (/Users/russell/lambda/gzip/node_modules/aws-sdk/lib/s3/managed

What are the purposes of vinyl-buffer and gulp-streamify in gulp?

那年仲夏 提交于 2019-11-30 11:07:54
As the documentation says, they both deal with transforming non-stream plugins to stream. What I try to understand is, if I can use the .pipe() method on something, doesn't it mean it's a stream? If so, what do I convert to what here? vinyl-source-stream example: (from: https://www.npmjs.com/package/vinyl-buffer ) var browserify = require('browserify') var source = require('vinyl-source-stream') var buffer = require('vinyl-buffer') var uglify = require('gulp-uglify') var size = require('gulp-size') var gulp = require('gulp') gulp.task('build', function() { var bundler = browserify('./index.js'

How to mock streams in NodeJS

 ̄綄美尐妖づ 提交于 2019-11-30 03:17:36
问题 I'm attempting to unit test one of my node-js modules which deals heavily in streams. I'm trying to mock a stream (that I will write to), as within my module I have ".on('data/end)" listeners that I would like to trigger. Essentially I want to be able to do something like this: var mockedStream = new require('stream').readable(); mockedStream.on('data', function withData('data') { console.dir(data); }); mockedStream.on('end', function() { console.dir('goodbye'); }); mockedStream.push('hello

How to implement a writable stream

我与影子孤独终老i 提交于 2019-11-28 15:47:27
I want to pipe data from an amazon kinesis stream to a an s3 log or a bunyan log. The sample works with a file write stream or stdout. How would I implmeny my own writable stream? //this works var file = fs.createWriteStream('my.log') kinesisSource.pipe(file) this doesn't work saying it has no method 'on' var stream = {}; //process.stdout works however stream.writable = true; stream.write =function(data){ console.log(data); }; kinesisSource.pipe(stream); what methods do I have to implement for my own custom writable stream, the docs seem to indicate I need to implement 'write' and not 'on'

Creating a Node.js stream from two piped streams

。_饼干妹妹 提交于 2019-11-28 06:27:38
I'd like to combine two Node.js streams into one by piping them, if possible. I'm using Transform streams. In other words, I'd like my library to return myStream for people to use. For example they could write: process.stdin.pipe(myStream).pipe(process.stdout); And internally I'm using a third-party vendorStream that does some work, plugged into my own logic contained in myInternalStream . So what's above would translate to: process.stdin.pipe(vendorStream).pipe(myInternalStream).pipe(process.stdout); Can I do something like that? I've tried var myStream = vendorStream.pipe(myInternalStream)

How to pipe one readable stream into two writable streams at once in Node.js?

让人想犯罪 __ 提交于 2019-11-27 20:26:35
The goal is to: Create a file read stream. Pipe it to gzip ( zlib.createGzip() ) Then pipe the read stream of zlib output to: 1) HTTP response object 2) and writable file stream to save the gzipped output. Now I can do down to 3.1: var gzip = zlib.createGzip(), sourceFileStream = fs.createReadStream(sourceFilePath), targetFileStream = fs.createWriteStream(targetFilePath); response.setHeader('Content-Encoding', 'gzip'); sourceFileStream.pipe(gzip).pipe(response); ... which works fine, but I need to also save the gzipped data to a file so that I don't need to regzip every time and be able to

How to implement a writable stream

徘徊边缘 提交于 2019-11-27 19:49:33
问题 I want to pipe data from an amazon kinesis stream to a an s3 log or a bunyan log. The sample works with a file write stream or stdout. How would I implmeny my own writable stream? //this works var file = fs.createWriteStream('my.log') kinesisSource.pipe(file) this doesn't work saying it has no method 'on' var stream = {}; //process.stdout works however stream.writable = true; stream.write =function(data){ console.log(data); }; kinesisSource.pipe(stream); what methods do I have to implement

Node.js: splitting stream content for n-parts

馋奶兔 提交于 2019-11-27 16:05:47
I'm trying to understand node streams and their life-cycle. So, I want to split the content of a stream for n-parts. The code below is just to explain my intentions and to show that I already try something by myself. I omitted some details I have a stream which just generates some data(just a sequence of numbers): class Stream extends Readable { constructor() { super({objectMode: true, highWaterMark: 1}) this.counter = 0 } _read(size) { if(this.counter === 30) { this.push(null) } else { this.push(this.counter) } this.counter += 1 } } const stream = new Stream() stream.pause(); a function which