Questions tagged [node.js-stream]

A stream is an abstract interface for working with streaming data in Node.js. The stream module provides a base API that makes it easy to build objects that implement the stream interface.

There are many stream objects provided by Node.js. For instance, a request to an HTTP server and process.stdout are both stream instances.

Streams can be readable, writable, or both. All streams are instances of EventEmitter.

The stream module can be accessed using:

const stream = require('stream');

There are four fundamental stream types within Node.js:

  • Readable - streams from which data can be read (for example fs.createReadStream()).
  • Writable - streams to which data can be written (for example fs.createWriteStream()).
  • Duplex - streams that are both Readable and Writable (for example net.Socket).
  • Transform - Duplex streams that can modify or transform the data as it is written and read (for example zlib.createDeflate()).
205 questions
0
votes
1 answer

How to force all stream done before we continue with other task?

I'm using node.js code to create a function to download an image from A repository and then upload to B repository. I want to force all streams to complete before it continues with other tasks. I have tried this way, but I have not been successful.…
0
votes
1 answer

How efficiently post a tweet with a remote image with Nodejs Stream?

I need to download a remote image, that its path is saved on the wineTweet.label attribut. And then POST a tweet with this image. My implementation is working, but I first save the image to a file and then read it before posting it. Here is the code…
Anthony
  • 3,989
  • 2
  • 30
  • 52
0
votes
1 answer

Node.js: variable to act as nested element name for an object

Here is my object: obj = { "FirstName": "Fawad", "LastName": "Surosh", "Education": {"University": "ABC", "Year": "2012"} } Here is my node.js code: var nodeName = 'Education.Year'; obj.nodeName; //this should return the…
0
votes
2 answers

require('use-strict') doesn't work for me

here, I am attempting to set value for read-only property but I am not getting any error: HERE IS MY CODE: require('use-strict'); function Employee(firstname) { var _firstname = firstname; Object.defineProperty(this, 'firstName', { …
0
votes
0 answers

Using "jsonfile" API throws error

var http = require('http'); var jsonfile = require('jsonfile'); var util = require('util'); http.createServer(function (req, resp) { if (req.method === "GET") { var file = "./files/file1.json"; jsonfile.readFile(file, function…
0
votes
1 answer

Chaining Node.js streams with run-time logic

I have been working with Node.js streams for the past 6 months or so, and I have been really happy with them so far. All of the problems I have encountered thus far, I have been able to solve using the standard template…
mevatron
  • 13,911
  • 4
  • 55
  • 72
0
votes
1 answer

Transform stream, accessing internal data

I want to read a file (ideally with fs.createReadStream, pipe it through a transform process and then write it (ideally using fs.createWriteStream) to another file. I am using a transform stream (new stream.Transform()) for this, and it seems to…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
0
votes
0 answers

Node.js. Why does this pipe throw: Error: write after end?

I wrote the next simply code: gulp.task('test', function () { var throughStream = through.obj(function (data, enc, next) { this.push(data); next(); }); function processStr(str, cb, parentStream) { var stream =…
Denis535
  • 3,407
  • 4
  • 25
  • 36
0
votes
0 answers

Piping Readable to Writable leads to crash

I have a Readable that generates an infinite sequence: var stream = require('stream'); var readable = new stream.Readable({ read: function (size) { for (;;) { var s = ' ' + (++this.count); if (!readable.push(s)) break; …
ycsun
  • 1,825
  • 1
  • 13
  • 21
0
votes
1 answer

Make Node.js stream info non-enumerable

I'm trying to omit this kind of data from a class that inherits from node.js-stream when doing a console.log(): asset: PassThrough { filename: 'old_man', data:
brandonscript
  • 68,675
  • 32
  • 163
  • 220
0
votes
1 answer

vinyl-fs (gulp file stream) not finishing .dest write before firing callback or promise

Frustratingly trying to get a vinyl-fs (gulpfs) stream to finish writing ALL the .dest files before launching code to upload a copy of the destination folder to an S3 bucket. That copy operation keeps missing a directory that the stream has yet to…
DKebler
  • 1,216
  • 1
  • 15
  • 27
0
votes
1 answer

How to write an image to a server having a Buffer?

In Expressjs I upload an image. It comes as a Buffer encoding 7bit: { fieldname: 'file', originalname: 'img.JPG', encoding: '7bit', mimetype: 'image/jpeg', buffer:
Green
  • 28,742
  • 61
  • 158
  • 247
0
votes
2 answers

What is the correct way to end a Gulp stream in progress?

I am converting a Grunt build task to a Gulp implementation. I am using gulp-watch, and this is what I've concocted to run my tasks: gulp.task('task', function(){ return watch('glob/**/*', function(){ var stream = doTask(); …
Bryan Rayner
  • 4,172
  • 4
  • 26
  • 38
0
votes
0 answers

Deleting a file (not unlinking) in Node.js

I am using node in Windows environment. When I use fs.unlink(fileName), it seems to work. After the unlink statement is executed when I go to the physical drive I could still see the file. At this point of time if I try and delete the file manually…
Sharath
  • 2,348
  • 8
  • 45
  • 81
0
votes
1 answer

Redirected console.log() to a file. Log file is not getting created again if log file is deleted manualy

I have redirected console.log() to a file(app_stdout.log) Next I run my program. app_stdout.log file is getting created. But If delete the log file manually when program is running then app_stdout.log file is not getting created again. Why? What Im…
Somnath
  • 3,247
  • 4
  • 28
  • 42