Index

lognestmonster / bc16689

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
3225 Dec 2018 23:56d01d51fUpdate fileHandler.jsJoshua1400N

Blob @ lognestmonster / src / fileHandler.js

application/javascript1147 bytesdownload raw
1const fs = require("fs");
2const path = require("path");
3
4class FileHandler {
5 static RecursiveMkdir(file) {
6 let currentFile = path.normalize(file);
7 let pathWorks = false;
8 let backToStart = false;
9 if (!fs.existsSync(path.normalize(file))) {
10 while (!pathWorks) {
11 if (fs.existsSync(path.normalize(currentFile))) {
12 pathWorks = true;
13 while (!backToStart) {
14 if (!fs.existsSync(path.dirname(currentFile))) {
15 fs.mkdirSync(path.dirname(currentFile));
16 }
17 if (fs.existsSync(path.normalize(file))) {
18 backToStart = true;
19 break;
20 }
21 currentFile = currentFile.slice(0, -3);
22 }
23 break;
24 } else {
25 currentFile += "\\.."
26 }
27 }
28 }
29 }
30 static AppendFile(file, data) {
31 if (typeof file != "string") throw new TypeError(`Expected string, got ${typeof file} for file`);
32 if (typeof data != "string") throw new TypeError(`Expected string, got ${typeof data} for data`);
33 if (!fs.existsSync(path.dirname(file))) {
34 FileHandler.RecursiveMkdir(path.dirname(file));
35 fs.appendFileSync(file, data);
36 } else fs.appendFileSync(file, data);
37 }
38}
39
40module.exports = FileHandler;
41