🪛 Switched to fs.promisified versions of fs utils

This commit is contained in:
2021-04-20 12:20:33 -07:00
parent a7f02c13e9
commit 2648970a27
2 changed files with 17 additions and 12 deletions

View File

@@ -12,9 +12,9 @@ import { Request, Response } from "express";
router.route("/getComicCovers").get(async (req: Request, res: Response) => { router.route("/getComicCovers").get(async (req: Request, res: Response) => {
const foo = await extractArchive({ const foo = await extractArchive({
name: "Hellboy - The Chained Coffin and Others Ch3.cbr", name: "Dollar Bill 001.cbr",
extension: ".cbr", extension: ".cbr",
containedIn: "comics/Hellboy. The Chained Coffin and Others (1998) (of 1)", containedIn: "comics/(2012) Before Watchmen - Dollar Bill",
isFile: true, isFile: true,
isLink: false, isLink: false,
}); });

View File

@@ -25,15 +25,15 @@ export const unrar = async (
> => { > => {
const comicCoversTargetPath = const comicCoversTargetPath =
extractionOptions.sourceFolder + extractionOptions.targetComicCoversFolder; extractionOptions.sourceFolder + extractionOptions.targetComicCoversFolder;
const fileBuffer = await fs
const buf = Uint8Array.from( .readFile(
fs.readFile(
extractionOptions.folderDetails.containedIn + extractionOptions.folderDetails.containedIn +
"/" + "/" +
extractionOptions.folderDetails.name, extractionOptions.folderDetails.name,
), )
).buffer; .catch((err) => console.error("Failed to read file", err));
const extractor = await unrarer.createExtractorFromData({ data: buf }); // const buf = Uint8Array.from(fs.readFile(fileBuffer);
const extractor = await unrarer.createExtractorFromData({ data: fileBuffer });
switch (extractionOptions.extractTarget) { switch (extractionOptions.extractTarget) {
// extract the first file only // extract the first file only
case "cover": case "cover":
@@ -84,19 +84,24 @@ export const unrar = async (
comicCoversTargetPath + "/" + pathFragments.exploded.join("/"); comicCoversTargetPath + "/" + pathFragments.exploded.join("/");
try { try {
await fse.ensureDir(targetPath, options); await fse.ensureDir(targetPath, options);
console.log("success!"); logger.info(`${targetPath} was created or already exists.`);
try { try {
await fs.writeFile(file.fileHeader.name, fileBuffer); // need to be in an async function await fs.writeFile(
targetPath + "/" + pathFragments.fileName,
fileBuffer,
);
comicBookCoverFiles.push({ comicBookCoverFiles.push({
name: `${file.fileHeader.name}`, name: `${file.fileHeader.name}`,
path: targetPath, path: targetPath,
fileSize: file.fileHeader.packSize, fileSize: file.fileHeader.packSize,
}); });
} catch (error) { } catch (error) {
console.log(error); logger.error(error);
reject(error);
} }
} catch (err) { } catch (err) {
console.error(err); logger.error(err);
reject(err);
} }
} }
resolve(comicBookCoverFiles); resolve(comicBookCoverFiles);