Index

lognestmonster / 84df067

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
4426 Dec 2018 23:21921db36Fix RecursiveMkdir, so that it works cross-platform.Patrik1628N

Blob @ lognestmonster / src / fileHandler.js

application/javascript794 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 fs.appendFileSync(file, data);
20 } else fs.appendFileSync(file, data);
21 }
22}
23
24module.exports = FileHandler;
25