🛫 unzip one file
This commit is contained in:
@@ -30,5 +30,5 @@ export interface IComicBookCoverMetadata {
|
|||||||
export interface IExtractedComicBookCoverFile {
|
export interface IExtractedComicBookCoverFile {
|
||||||
name: string;
|
name: string;
|
||||||
path: string;
|
path: string;
|
||||||
fileSize: string;
|
fileSize: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
unrar,
|
unrar,
|
||||||
unzip,
|
unzip,
|
||||||
extractMetadataFromImage,
|
extractMetadataFromImage,
|
||||||
|
unzipOne,
|
||||||
} from "../../utils/fs.utils";
|
} from "../../utils/fs.utils";
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
|
|
||||||
@@ -13,7 +14,8 @@ router.route("/getComicCovers").get(async (req: Request, res: Response) => {
|
|||||||
// const foo = await extractMetadataFromImage(
|
// const foo = await extractMetadataFromImage(
|
||||||
// "./comics/covers/Ghosts and Ruins-001.jpg",
|
// "./comics/covers/Ghosts and Ruins-001.jpg",
|
||||||
// );
|
// );
|
||||||
const foo = await unzip("st");
|
// const foo = await unzipOne();
|
||||||
|
const foo = await unzip("asd");
|
||||||
res.json({
|
res.json({
|
||||||
jagan: "trupti",
|
jagan: "trupti",
|
||||||
foo,
|
foo,
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export const unrar = async (
|
|||||||
resolve({
|
resolve({
|
||||||
name: `${extractedFile.fileHeader.name}`,
|
name: `${extractedFile.fileHeader.name}`,
|
||||||
path: `${filePath}`,
|
path: `${filePath}`,
|
||||||
fileSize: `${extractedFile.fileHeader.packSize}`,
|
fileSize: extractedFile.fileHeader.packSize,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -64,8 +64,8 @@ export const extractMetadataFromImage = async (
|
|||||||
|
|
||||||
export const unzip = async (
|
export const unzip = async (
|
||||||
filePath: string,
|
filePath: string,
|
||||||
): Promise<IExtractedComicBookCoverFile> => {
|
): Promise<IExtractedComicBookCoverFile[]> => {
|
||||||
let foo: IExtractedComicBookCoverFile = { name: "", path: "", fileSize: "" };
|
const foo: IExtractedComicBookCoverFile[] = [];
|
||||||
const zip = fs
|
const zip = fs
|
||||||
.createReadStream(
|
.createReadStream(
|
||||||
"./comics/Lovecraft - The Myth of Cthulhu (2018) (Maroto) (fylgja).cbz",
|
"./comics/Lovecraft - The Myth of Cthulhu (2018) (Maroto) (fylgja).cbz",
|
||||||
@@ -73,14 +73,13 @@ export const unzip = async (
|
|||||||
.pipe(unzipper.Parse({ forceStream: true }));
|
.pipe(unzipper.Parse({ forceStream: true }));
|
||||||
for await (const entry of zip) {
|
for await (const entry of zip) {
|
||||||
const fileName = entry.path;
|
const fileName = entry.path;
|
||||||
const type = entry.type; // 'Directory' or 'File'
|
|
||||||
const size = entry.vars.uncompressedSize; // There is also compressedSize;
|
const size = entry.vars.uncompressedSize; // There is also compressedSize;
|
||||||
foo = {
|
foo.push({
|
||||||
name: fileName,
|
name: fileName,
|
||||||
fileSize: size,
|
fileSize: size,
|
||||||
path: filePath,
|
path: filePath,
|
||||||
};
|
});
|
||||||
entry.pipe(fs.createWriteStream("./comics/covers/cover.jpg"));
|
entry.pipe(fs.createWriteStream("./comics/covers/" + fileName));
|
||||||
entry.autodrain();
|
entry.autodrain();
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -88,6 +87,25 @@ export const unzip = async (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const unzipOne = async (): Promise<IExtractedComicBookCoverFile> => {
|
||||||
|
const directory = await unzipper.Open.file(
|
||||||
|
"./comics/Lovecraft - The Myth of Cthulhu (2018) (Maroto) (fylgja).cbz",
|
||||||
|
);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
directory.files[0]
|
||||||
|
.stream()
|
||||||
|
.pipe(fs.createWriteStream("./comics/covers/yelaveda.jpg"))
|
||||||
|
.on("error", reject)
|
||||||
|
.on("finish", () =>
|
||||||
|
resolve({
|
||||||
|
name: directory.files[0].path,
|
||||||
|
fileSize: directory.files[0].uncompressedSize,
|
||||||
|
path: "ll",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const extractArchive = async (
|
export const extractArchive = async (
|
||||||
fileObject: IFolderData,
|
fileObject: IFolderData,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
|
|||||||
Reference in New Issue
Block a user