Added ability to output the buffer #95

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@dakatsuka

I've added ability to output the buffer.

Example:

var fs = require('fs');
var request = require('request');
var options = {
  method: 'GET',
  uri: "http://foobar.foo/profile.png",
  output: "buffer"
};

request.get(options, function(error, response, body) {
  console.log(body instanceof Buffer); // => true
  fs.writeFile("profile.png", body);
});

Is it possible for you to merge this commit into your repository?

Regards,
Dai Akatsuka.

@mikeal
Member
mikeal commented Oct 26, 2011

what use case do you have for buffering the data and not converting it to a string?

usually when you want to keep it as a buffer you stream it (which disables buffering the bode entirely).

@dakatsuka

I think trying to use websocket (Node-WebSocket) for binary transfer of data.
Argument of sendBytes uses an instance of Buffer. SendBytes can directly be used if response hold the buffer.

websocket.on('connect', function(connection) {
  // snip

  request.get(options, function(error, response, body) {
    connection.sendBytes(body);
  });

  // snip
});
@mikeal
Member
mikeal commented Feb 18, 2012

needs to be rebased. closing for now.

@mikeal mikeal closed this Feb 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment