我正在学习节点,在下面的程序中,我收到警告声明:
“(node:93236)[DEP0013] DeprecationWarning:调用异步 没有回调的功能是 弃用“。(https://nodejs.org/api/deprecations.html#deprecations_dep0013_fs_asynchronous_function_without_callback)
脚本:
var fs = require('fs');
fs.open('test.txt', 'r', function (err, handle) {
if (err == null) {
var f = handle;
var b = new Buffer(100000);
fs.read(f, b, 0, 100000, null, function (err, bytes_read) {
if (err == null) {
console.log(b.toString("utf8", 0, bytes_read));
} else {
console.log("Oh Noes! fail on read: " + err.code + " " + err.message);
}
fs.close(f);
});
} else {
console.log("Oh noes! fail an open: " + err.code + " " + err.message);
}
});
我应该如何进行以找到如何在这些函数fs.open(...)和fs.read(...)中正确包含回调函数? 谢谢!