Skip to content

Latest commit

 

History

History
executable file
·
68 lines (46 loc) · 2.03 KB

README.md

File metadata and controls

executable file
·
68 lines (46 loc) · 2.03 KB

empty-file

NPM version Build Status Coverage Status Dependency Status devDependency Status

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'); //=> ''
});

Installation

Use npm.

npm install empty-file

API

const emptyFile = require('empty-file');

emptyFile(filePath[, options])

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);

Related project

License

The Unlicense