B
B
babbert2019-04-18 21:49:27
Node.js
babbert, 2019-04-18 21:49:27

How to make your fs wrapper?

Hello.
I have a wrapper around some fs functions, but I need to make an exact copy for fs.readdir and fs.createWriteStream.
Current code:

const fs = require('fs');

exports.mkdir = async function(dirArr) {
  for(dir of dirArr) await fs.mkdir(dir, (e) => {err(e)});
}

exports.unlink = async function(linkArr) {
  for(link of linkArr) await fs.unlink(link, (e) => {err(e)});
}

exports.rmdir = async function(dirArr) {
  for(dir of dirArr) await fs.rmdir(dir, (e) => {err(e)});
}

exports.readFile = function(file, encoding = 'utf8') {
  try {
    return fs.readFileSync(file, encoding);
  } catch(e) {
    err(e);
  }
}

function err(e) {
  if(e) echo(`   [E] ${e}`);
}

It is necessary, somehow just to forward in exports.readdir => fs.readdir
I hope for the local help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2019-04-18
@babbert

const fs = require('fs');

...

exports.readdir = fs.readdir;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question