UNPKG

973 BJavaScriptView Raw
1"use strict";
2
3const { execSync } = require("child_process");
4const { internalModuleStat } = process.binding("fs");
5const { readdirSync, readFileSync, copyFileSync, writeFileSync } = require("fs");
6
7module.exports.write = function ({ path, contents, encoding }) {
8 return writeFileSync(path, contents, encoding);
9};
10
11module.exports.copy = function ({ source, destination }) {
12 return copyFileSync(source, destination);
13};
14
15module.exports.read = function read({ path, encoding }) {
16 return readFileSync(path, encoding);
17};
18
19module.exports.readdir = function readdir({ path }) {
20 return readdirSync(path);
21};
22
23module.exports.mkdirp = function mkdirp({ path }) {
24 execSync(`mkdir -p ${JSON.stringify(path)}`);
25};
26
27module.exports.tstat = function tstat({ path }) {
28 const type = internalModuleStat(path);
29
30 if (type < 0) return "ENOENT";
31
32 if (type === 0) return "file";
33
34 if (type === 1) return "directory";
35
36 throw new Error("Unknown Error");
37};
\No newline at end of file