This repository has been archived by the owner on Jan 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (61 loc) · 1.53 KB
/
index.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
60
61
62
63
64
65
66
67
68
69
70
71
const os = require("os");
const fs = require("fs");
const path = require("path");
const BIN_PATH_WIN32 = "C://$Recycle.Bin/";
/**
* This function returns the path according to the Operating System
* @return {string} The path to the recycle bin
*/
function getBinPath() {
const platform = os.platform();
switch(platform) {
case "win32":
return BIN_PATH_WIN32;
default:
throw new Error("Unable to find the architecture of this machine!");
}
}
class BinShell {
/**
* Reads the directory asynchronously
* @param {(err: Error, data: string[]) => void} callback
* @param {{
* encoding: BufferEncoding,
* withFileTypes?: false
* } | BufferEncoding} options
* @returns {void}
*/
static readBin(callback, options) {
const asyncData = fs.readdir(getBinPath(), options || {
encoding: "utf-8"
}, (err, data) => {
callback(err, data);
});
return asyncData;
}
/**
* Cleans the Recycle Bin
*/
static cleanBin() {
// TODO:
}
/**
*
* @param {{
* encoding: BufferEncoding,
* withFileTypes?: false
* } | BufferEncoding} options
* @returns
*/
static readBinSync(options) {
const syncData = fs.readdirSync(getBinPath(), options || "utf-8");
return syncData;
}
/**
* @returns {string} The path to Recycle bin
*/
get binPath() {
return getBinPath();
}
}
module.exports = BinShell;