@w3bstream/w3bstream-http-client-simulator
Version:
[](https://www.npmjs.com/package/@w3bstream/w3bstream-http-client-simulator)
28 lines (27 loc) • 709 B
JavaScript
import fs from "fs";
import path from "path";
export class FileNotFound extends Error {
}
export class ErrorSavingFile extends Error {
}
export class PrivateKeyFile {
static getFromPath(pathToPk) {
try {
const filePath = path.join(pathToPk, "private.key");
const privateKey = fs.readFileSync(filePath);
return privateKey.toString();
}
catch (err) {
throw new FileNotFound();
}
}
static save(privateKey) {
const newPath = path.join("./", "private.key");
try {
fs.writeFileSync(newPath, privateKey);
}
catch (err) {
throw new ErrorSavingFile();
}
}
}