44 lines
1016 B
JavaScript
44 lines
1016 B
JavaScript
const fs = require('fs');
|
|
|
|
module.exports = {
|
|
async writeFile(path, content, options)
|
|
{
|
|
return await new Promise((ok, no) =>
|
|
{
|
|
fs.writeFile(path, content, options, err => err ? no(err) : ok());
|
|
});
|
|
},
|
|
|
|
async rename(from, to)
|
|
{
|
|
return await new Promise((ok, no) =>
|
|
{
|
|
fs.rename(from, to, err => err ? no(err) : ok());
|
|
});
|
|
},
|
|
|
|
async mkdir(path, options)
|
|
{
|
|
return await new Promise((ok, no) =>
|
|
{
|
|
fs.mkdir(path, options, err => err ? no(err) : ok());
|
|
});
|
|
},
|
|
|
|
async exists(path)
|
|
{
|
|
return await new Promise((ok, no) =>
|
|
{
|
|
fs.access(path, fs.constants.R_OK, err => err ? (err.code == 'ENOENT' ? ok(false) : no(err)) : ok(true));
|
|
});
|
|
},
|
|
|
|
async is_writable(path)
|
|
{
|
|
return await new Promise((ok, no) =>
|
|
{
|
|
fs.access(path, fs.constants.R_OK | fs.constants.W_OK, err => ok(!err));
|
|
});
|
|
},
|
|
};
|