🗜 Fixing the unzip method

This commit is contained in:
2021-04-17 16:02:12 -07:00
parent 424c5aded7
commit dc2153e19c
3 changed files with 33 additions and 15 deletions

View File

@@ -30,4 +30,5 @@ export interface IComicBookCoverMetadata {
export interface IExtractedComicBookCoverFile {
name: string;
path: string;
fileSize: string;
}

View File

@@ -3,15 +3,17 @@ import {
walkFolder,
extractArchive,
unrar,
unzip,
extractMetadataFromImage,
} from "../../utils/fs.utils";
import { Request, Response } from "express";
router.route("/getComicCovers").get(async (req: Request, res: Response) => {
// unrar("./comics/covers/");
const foo = await extractMetadataFromImage(
"./comics/covers/Ghosts and Ruins-001.jpg",
);
// const foo = await unrar("./comics/covers/");
// const foo = await extractMetadataFromImage(
// "./comics/covers/Ghosts and Ruins-001.jpg",
// );
const foo = await unzip("st");
res.json({
jagan: "trupti",
foo,

View File

@@ -2,6 +2,7 @@ import { default as unzipper } from "unzipper";
const etl = require("etl");
const sharp = require("sharp");
const imgHash = require("imghash");
const stream = require("stream");
const unrarer = require("node-unrar-js");
const Walk = require("@root/walk");
import fs from "fs";
@@ -43,6 +44,7 @@ export const unrar = async (
resolve({
name: `${extractedFile.fileHeader.name}`,
path: `${filePath}`,
fileSize: `${extractedFile.fileHeader.packSize}`,
});
}
});
@@ -60,17 +62,30 @@ export const extractMetadataFromImage = async (
return image;
};
export const unzip = () => {
fs.createReadStream("./comics/30 Days of Night 01-003.cbz")
.pipe(unzipper.ParseOne())
.pipe(etl.toFile("./comics/covers/cover.jpg"))
.promise()
.then(() => {
logger.info("done");
})
.catch((e) => {
logger.info("error", e);
});
export const unzip = async (
filePath: string,
): Promise<IExtractedComicBookCoverFile> => {
let foo: IExtractedComicBookCoverFile = { name: "", path: "", fileSize: "" };
const zip = fs
.createReadStream(
"./comics/Lovecraft - The Myth of Cthulhu (2018) (Maroto) (fylgja).cbz",
)
.pipe(unzipper.Parse({ forceStream: true }));
for await (const entry of zip) {
const fileName = entry.path;
const type = entry.type; // 'Directory' or 'File'
const size = entry.vars.uncompressedSize; // There is also compressedSize;
foo = {
name: fileName,
fileSize: size,
path: filePath,
};
entry.pipe(fs.createWriteStream("./comics/covers/cover.jpg"));
entry.autodrain();
}
return new Promise((resolve, reject) => {
resolve(foo);
});
};
export const extractArchive = async (