|
1 | 1 | "use strict"; |
2 | 2 | Object.defineProperty(exports, "__esModule", { value: true }); |
3 | 3 | exports.processPath = void 0; |
4 | | -const fs = require("fs"); |
| 4 | +const fs = require("fs/promises"); |
5 | 5 | const path = require("path"); |
6 | 6 | const workerPool_1 = require("./workerPool"); |
7 | 7 | /** |
8 | 8 | * Processes all files in the specified directory with the given image processing options. |
9 | 9 | */ |
10 | | -function processPath(directoryPath, options, maxWorkers) { |
| 10 | +async function processPath(directoryPath, options, maxWorkers) { |
11 | 11 | const workerPool = new workerPool_1.WorkerPool(maxWorkers); |
12 | | - // Read the contents of the directory |
13 | | - fs.readdir(directoryPath, (err, files) => { |
14 | | - if (err) { |
15 | | - console.error(`Error reading directory: ${directoryPath}`, err); |
16 | | - return; |
17 | | - } |
| 12 | + try { |
| 13 | + const files = await fs.readdir(directoryPath); |
18 | 14 | // Add each file as a task to the worker pool |
19 | | - files.forEach((file) => { |
| 15 | + for (const file of files) { |
20 | 16 | const filePath = path.join(directoryPath, file); |
21 | 17 | // Check if it's a file (not a subdirectory) |
22 | | - if (fs.statSync(filePath).isFile()) { |
| 18 | + if ((await fs.stat(filePath)).isFile()) { |
23 | 19 | workerPool.addTask(filePath, options); |
24 | 20 | } |
25 | | - }); |
| 21 | + } |
26 | 22 | // Wait for all tasks to complete before exiting |
27 | 23 | workerPool.waitForCompletion(); |
28 | | - }); |
| 24 | + } |
| 25 | + catch (err) { |
| 26 | + console.error(`Error reading directory: ${directoryPath}`, err); |
| 27 | + } |
29 | 28 | } |
30 | 29 | exports.processPath = processPath; |
0 commit comments