A Node module to write an empty file asynchronously
const emptyFile = require('empty-file');
const fs = require('fs');
emptyFile('file/path').then(() => {
fs.readFileSync('file/path', 'utf8'); //=> ''
});
npm install empty-file
const emptyFile = require('empty-file');
filePath: String
options: Object
(fs.writeFile
options except for encoding
)
Return: Object
(Promise instance)
It writes new Buffer(0)
to a file.
When it finish writing a file, it will be fulfilled with no arguments.
When it fails, it will be rejected with an error object.
const emptyFile = require('empty-file');
const fs = require('fs');
function onFulfilled() {
fs.readFileSync('tmp', 'utf8'); //=> ''
fs.statSync('tmp').mode; //=> 33261
}
function onRejected(err) {
console.error(err.message);
}
emptyFile('tmp', {mode: 33261}).then(onFulfilled, onRejected);
- empty-file-callback (callback-style version)