跳到主要内容

FileHandle

2024年10月14日
柏拉文
越努力,越幸运

一、FileHandle


二、Event: 'close'


三、filehandle.appendFile(data[, options])


语法

filehandle.appendFile(data: string|buffer|typeArray|dataView|asyncIterable|stream|iterable,options: {
encoding: string|null
})
  • encoding: string|null, 默认值为 "utf8"

场景

const Fs = require('fs');

async function append(path,content){
let filehandle = null;
try{
filehandle = await Fs.promises.open(path,mode='a');
await filehandle.appendFile(content);
}catch(error){
console.log(error);
}finally{
await filehandle?.close();
}
}

append('./test.js','哈哈哈');

四、filehandle.chmod(mode)


五、filehandle.chown(uid, gid)


六、filehandle.close()


七、filehandle.createReadStream([options])


八、filehandle.createWriteStream([options])


九、filehandle.datasync()


十、filehandle.fd


十一、filehandle.read(buffer, offset, length, position)


十二、filehandle.read([options])


十三、filehandle.read(buffer[, options])


十四、filehandle.readableWebStream([options])


十五、filehandle.readFile(options)


十六、filehandle.readLines([options])


十七、filehandle.readv(buffers[, position])


十八、filehandle.stat([options])


十九、filehandle.sync()


二十、filehandle.truncate(len)


二十一、filehandle.utimes(atime, mtime)


二十二、filehandle.write(buffer, offset[, length[, position]])


二十三、filehandle.write(buffer[, options])


二十四、filehandle.write(string[, position[, encoding]])


二十五、filehandle.writeFile(data, options)


二十六、filehandle.writev(buffers[, position])


二十七、filehandle[Symbol.asyncDispose]()


参考资料


Node.js 中文网