Skip to content

hehe100596/empty-file

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Write an empty file asynchronously

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%