-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive.js
59 lines (52 loc) · 1.01 KB
/
archive.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"use strict";
/*
* Saves all read traffic information to a user data folder
*/
const path = require("path");
const fs = require("fs");
const Tools = require("./tools.js");
var DIR = "";
var initSucessful = false;
function init() {
try {
const base = process.env.APPDATA || process.env.HOME;
const dir = path.join(base, "plabutschor");
Tools.log("Archive: " + dir);
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
DIR = dir;
initSucessful = true;
}
catch(ex) {
Tools.log("Error on archive.init: " + ex);
}
}
function clear() {
if(!initSucessful)
return;
fs.readdir(DIR, (err, files) => {
if (err)
throw err;
for (const file of files) {
fs.unlink(path.join(DIR, file), err => {
if (err)
throw err;
});
}
});
}
function store(data) {
if(!initSucessful)
return;
var file = path.join(DIR, String(new Date().getTime()) + ".json");
fs.writeFile(file, data);
Tools.log("Wrote: " + file);
}
init();
if(typeof module !== "undefined") {
module.exports = {
store,
clear
};
}