【发布时间】:2018-11-21 17:35:06
【问题描述】:
以下代码块将content 变量留空:
const file = fs.createWriteStream("/home/pi/rpi-main/descriptor.json");
http.get(url, function (response) {
let content;
response.pipe(file);
content = fs.readFileSync("/home/pi/rpi-main/descriptor.json", { encoding: "utf-8" });
});
但是,如果我使用 fs.readFile 读取文件,内容就是它应有的内容。
为什么同步调用会发生这种情况?
【问题讨论】:
-
您在代码中的哪个位置使用
content?