i'm fetching some binary data over http. My code looks like:
var writeStream = fs.createWriteStream(fileName);
request(url, function(err, res) {
res.socket.pipe(writeStream);
});
now the output file is created but the filesize is 0. The url is correct though, i verified that with wget.
Thanks in advance & best regards
I'm assuming that here
request
is from mikeal's request library rather than being an instance ofhttp.request
. In that case you can simply dorequest(url).pipe(writeStream);
Remember that for debugging purposes, you can always pipe to
process.stdout
.The callback for
http.request
only supplies one argument, which is a reference to the response of the request. TryAlso note that the
ClientResponse
implementsReadableStream
, so you should use.pipe
rather than.socket.pipe
.