-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileLoader.js
More file actions
35 lines (27 loc) · 697 Bytes
/
FileLoader.js
File metadata and controls
35 lines (27 loc) · 697 Bytes
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
// @ts-check
const fs = require("fs-extra");
const path = require("path");
class FileLoader
{
constructor()
{
}
/**
* @param {string} strFileName
*/
static async readFile(strFileName)
{
if(path.extname(strFileName).toLowerCase() !== ".txt")
{
throw new Error("Input file must have '.txt' extension.");
}
const strInputFilePath = path.join(__dirname, strFileName);
if(!(await fs.stat(strInputFilePath)).isFile())
{
throw new Error(`Input file with the name: ${strFileName} was not found in: ${strInputFilePath}`);
}
const strFileContents = await fs.readFile(strInputFilePath, {encoding: "utf8"});
return strFileContents;
}
}
module.exports = FileLoader;