【发布时间】:2018-02-13 17:09:51
【问题描述】:
我希望的简单问题...
我想将 Node 文档网站中的以下代码用于 HTTPS (https://nodejs.org/api/https.html),但我想将其写入文件而不是 stdout。
const https = require('https');
https.get('https://encrypted.google.com/', (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
});
}).on('error', (e) => {
console.error(e);
});
我找到了以下用于编写二进制文件的 FS 代码,但似乎无法成功地将两者放在一起。
var crypto = require('crypto');
var fs = require('fs');
var wstream = fs.createWriteStream('myBinaryFile');
// creates random Buffer of 100 bytes
var buffer = crypto.randomBytes(100);
wstream.write(buffer);
// create another Buffer of 100 bytes and write
wstream.write(crypto.randomBytes(100));
wstream.end();
有什么想法吗?
【问题讨论】:
标签: node.js https stream binary chunks