Reputation: 123
Alright. Have these 2 pieces of code:
// first example
request(imageUrl).then((data) => {
var wstream = fs.createWriteStream('doodle');
wstream.write(data);
})
// second example
request(imageUrl).pipe(fs.createWriteStream('doodle2'));
What I try to do is to save an image to disk. Second example works fine. But my question is: both examples do same task, but why do they produce different results? Btw thats request-promise module in examples.
Upvotes: 2
Views: 8067
Reputation: 381
var request = require("request-promise");
var fs = require("fs");
var imageUrl = "http://www.biografiasyvidas.com/biografia/m/fotos/mandela_nelson_5.jpg";
request({
"uri":imageUrl,
"encoding": null
}).then((data) => {
var wstream = fs.createWriteStream('doodle.jpg');
wstream.write(data);
});
Encoding must be null in that case. See the README.md, search encoding https://github.com/request/request
Upvotes: 8