作为文件的node.js回调fs.write不工作作为文件
fs.write(FD,缓冲器,偏移,长度,位置,[回调])
所以我写如:
var fs = require('fs');
fs.open('./example.txt', 'a', 0666, function(err, fd) {
if (err) { throw err; }
console.log('file opened');
fs.write(fd, 'test', null, null, null, function(err) {
if (err) { throw err; }
console.log('file written');
fs.close(fd, function() {
console.log('file closed');
});
});
});
但fs.write的回调没有被触发。输出只是'文件打开'。
fs.write(fd, 'test', null, null, function(err) {
但我指定第5个参数不是第6个参数的回调。这是作品。 为什么与文档不同。
并在节点源(node_file.cc)中回调是第6个参数。
Local<Value> cb = args[5];
我不明白。
和fs.open中的0666是什么意思? – Outsider