2024-08-16 15:04:52 -04:00
|
|
|
import fs from "fs";
|
2024-08-17 01:39:16 -04:00
|
|
|
import { Review } from "../types";
|
2024-08-16 15:04:52 -04:00
|
|
|
|
|
|
|
export function checkFile(file: string, encoding: fs.EncodingOption): Review[] {
|
2024-08-17 12:56:35 -04:00
|
|
|
const dir = "./persist/";
|
2024-08-16 15:04:52 -04:00
|
|
|
const fullPath = dir + file;
|
|
|
|
let final: Review[];
|
|
|
|
|
|
|
|
if (fs.existsSync(dir)) {
|
|
|
|
const data = fs.readFileSync(fullPath, encoding);
|
|
|
|
|
|
|
|
final = !data.toString().trim() ? [] : JSON.parse(data.toString());
|
|
|
|
} else {
|
|
|
|
fs.mkdirSync(dir);
|
|
|
|
fs.createWriteStream(fullPath);
|
|
|
|
final = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return final;
|
|
|
|
}
|