@kadena/kadena-cli
Version:
Kadena CLI tool to interact with the Kadena blockchain (manage keys, transactions, etc.)
74 lines • 2.12 kB
JavaScript
import { vol } from 'memfs';
import { dirname } from 'path';
export const fs = vol.promises;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const memoryFsToJson = () => vol.toJSON();
export const memoryFileSystemService = {
readFileSync(path) {
try {
return vol.readFileSync(path, 'utf8');
}
catch (e) {
return null;
}
},
async readFile(path) {
try {
return (await fs.readFile(path, 'utf8'));
}
catch (e) {
return null;
}
},
async writeFile(path, data) {
await fs.writeFile(path, data, { encoding: 'utf8' });
},
async deleteFile(path) {
await fs.unlink(path);
},
async deleteDirectory(path) {
await fs.rm(path, { recursive: true });
},
async directoryExists(path) {
try {
const stat = await fs.stat(path);
return stat.isDirectory();
}
catch {
return false;
}
},
async fileExists(path) {
try {
const stat = await fs.stat(path);
return stat.isFile();
}
catch {
return false;
}
},
async ensureDirectoryExists(path) {
var _a, _b;
if (await memoryFileSystemService.directoryExists(path))
return;
const isFile = (_b = (_a = path.split('/').pop()) === null || _a === void 0 ? void 0 : _a.includes('.')) !== null && _b !== void 0 ? _b : false;
await fs.mkdir(isFile ? dirname(path) : path, {
recursive: true,
});
},
async readDir(path) {
const result = await fs.readdir(path);
return result.map((file) => file.toString());
},
async readDirWithTypes(path) {
const result = await fs.readdir(path, { withFileTypes: true });
return result;
},
async appendFile(path, data) {
await fs.appendFile(path, data, { encoding: 'utf8' });
},
async lstat(path) {
return fs.lstat(path);
},
};
//# sourceMappingURL=fs.memory.service.js.map