Skip to content

Commit

Permalink
simplify the code using Node.js >= 8 features
Browse files Browse the repository at this point in the history
* util.promisify()
* async/await

[BREAKING] drop support for Node.js < 8
  • Loading branch information
shinnn committed Jul 18, 2017
1 parent 1a0260f commit dea9411
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@
*/
'use strict';

const fs = require('graceful-fs');
const runSeries = require('run-series');
const {promisify} = require('util');
const {readFile, unlink} = require('graceful-fs');

module.exports = function readRemoveFile(filePath, options) {
return new Promise((resolve, reject) => {
runSeries([
cb => fs.readFile(filePath, options, cb),
cb => fs.unlink(filePath, cb)
], (err, results) => {
if (err) {
reject(err);
return;
}
const readFileP = promisify(readFile);
const unlinkP = promisify(unlink);

resolve(results[0]);
});
});
module.exports = async function readRemoveFile(filePath, options) {
const data = await readFileP(filePath, options);
await unlinkP(filePath);

return data;
};

0 comments on commit dea9411

Please sign in to comment.