1.0.1 • Published 8 years ago

empty-file v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

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