Index

lognestmonster / 2f036c3

A general-purpose single-header C logging library and parser for event-based logs. (Incomplete)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
5127 Dec 2018 21:40c1f639dUpdate fileHandler.jsJoshua122N

Blob @ lognestmonster / src / fileHandler.js

application/javascript757 bytesdownload raw
1const fs = require("fs");
2const path = require("path");
3
4class FileHandler {
5 static RecursiveMkdir(file) {
6 let paths = path.normalize(file).split(path.sep);
7 let curPath = (path.isAbsolute(file)) ? "" : ".";
8 for (var i = 0; i < paths.length; i++) {
9 curPath += path.sep + paths[i];
10 if (!fs.existsSync(curPath))
11 fs.mkdirSync(curPath);
12 }
13 }
14 static AppendFile(file, data) {
15 if (typeof file != "string") throw new TypeError(`Expected string, got ${typeof file} for file`);
16 if (typeof data != "string") throw new TypeError(`Expected string, got ${typeof data} for data`);
17 if (!fs.existsSync(path.dirname(file))) {
18 FileHandler.RecursiveMkdir(path.dirname(file));
19 }
20 fs.appendFileSync(file, data);
21 }
22}
23
24module.exports = FileHandler;
25