added 2 binary exemple

Got to many "how do i handle binary/images" issues
This commit is contained in:
Jimmy Karl Roland Wärting 2016-08-16 11:40:31 +02:00 committed by GitHub
parent 4e455a4185
commit d8c6969736
1 changed files with 18 additions and 1 deletions

View File

@ -64,7 +64,24 @@ fetch('https://api.github.com/users/github')
console.log(json);
});
// since v1.6.0, there is also res.buffer() for convenience
// Binary
// The perfered way is to use the stream's
// when working with larger binaries
fetch('some.png')
.then(function(res) {
var dest = fs.createWriteStream('./img/some.png');
res.body.pipe(dest);
})
// When working with smaller binaries like
// with protobuf it can be good to use .buffer()
fetch('http://example.com/api/proto')
.then(function(res) {
return res.buffer();
}).then(function(buffer) {
console.log(buffer);
});
// meta