Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Pipe response inside callbacks #364

Closed
chrisjenx opened this Issue · 2 comments

2 participants

@chrisjenx

Hi im trying to pipe inside the response.

request(s,function (error, response, body) {
  if (!error && response.statusCode == 200) {
    body.pipe(fs.createWriteStream(ORGINAL_IMAGE_PATH+'image.jpg'));
  }
});

Of course this doesn't work. How would I pipe the body(image to the file).
fyi the folder does exist as request(s).pipe(...) works fine.

Cheers,
Chris

@mikeal
Owner

the callbacks waits for the entire response body to buffer, so that won't work. this is what you want.

var req = request(url)
req.on('response', function (resp) {
  if (resp.statusCode === 200) req.pipe(destination)
})
@chrisjenx

Splendid works like charm, worth adding to the readme? Many thanks!

@chrisjenx chrisjenx closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.