🔧 Refactored the folder size calculator function
This commit is contained in:
@@ -2,6 +2,7 @@ const Walk = require("@root/walk");
|
|||||||
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
const { readdir, stat } = require("fs/promises");
|
||||||
import {
|
import {
|
||||||
IExplodedPathResponse,
|
IExplodedPathResponse,
|
||||||
IExtractComicBookCoverErrorResponse,
|
IExtractComicBookCoverErrorResponse,
|
||||||
@@ -67,16 +68,16 @@ export const explodePath = (filePath: string): IExplodedPathResponse => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getSizeOfDirectory = async (
|
export const getSizeOfDirectory = async (
|
||||||
path: string,
|
directoryPath: string,
|
||||||
extensions: string[]
|
extensions: string[]
|
||||||
) => {
|
) => {
|
||||||
const arrayOfFiles = await walkFolder(path, extensions);
|
const files = await readdir(directoryPath);
|
||||||
let totalSize = 0;
|
const stats = files.map((file) => stat(path.join(directoryPath, file)));
|
||||||
|
|
||||||
arrayOfFiles.forEach((file) => {
|
return (await Promise.all(stats)).reduce(
|
||||||
totalSize += file.fileSize;
|
(accumulator, { size }) => accumulator + size,
|
||||||
});
|
0
|
||||||
return totalSize;
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isValidImageFileExtension = (fileName: string): boolean => {
|
export const isValidImageFileExtension = (fileName: string): boolean => {
|
||||||
|
|||||||
Reference in New Issue
Block a user