I study binary data. I can not figure out the following:
I get the image from the network:
var request = require('request'); var fs = require('fs'); var options = { url: 'url', // encoding: 'binary' // понимаю, что можно использовать, но хотелось бы самому.. } request(options, function (error, response, body) { if (!error && response.statusCode == 200) { var data = new Buffer(body); fs.writeFile('image.png', data, 'binary'); console.log(data); } }) conclusion:
PNG IHDR 2 4IDAT 5 =O QF . " % : HLLH |` U 4 ~ ~ G /x qw L& v{| Kr h6 E R"x > j q Q r I, |=9b # , N13$yY . ^kL 9& < V }dsg 1 gQ ? V6 W vcI ; pwJoj ; hb E )%r $r < T G NIEND B` After writing this data to a local file, the image does not want to be displayed.
Interested in: What is the type of data that I get? Is this not binary data? How to do right?