MCPcopy Create free account
hub / github.com/TechJeeper/Printventory / scanZipFile

Function scanZipFile

scan-worker.js:356–406  ·  view source on GitHub ↗
(zipPath, maxFileSize, extSet = new Set(['.stl', '.3mf']))

Source from the content-addressed store, hash-verified

354 });
355 flushDiscoveredFiles();
356 }
357 } else if (enableZipArchives && ext === '.zip') {
358 // Scan inside ZIP using same scanExtensions
359 // ZIP files still need stat for size check
360 const stats = await fs.promises.stat(filePath);
361 if (stats.size <= maxFileSize) {
362 const zipFiles = await scanZipFile(filePath, maxFileSize, extSet);
363 files.push(...zipFiles);
364 flushDiscoveredFiles();
365 }
366 }
367 // For all other files, do nothing - no stat() call!
368 } catch (error) {
369 console.error(`Error processing file ${filePath}:`, error);
370 }
371 };
372
373 // Start processing
374 processNext();
375
376 return donePromise;
377}
378
379 async function scanZipFile(zipPath, maxFileSize, extSet = new Set(['.stl', '.3mf'])) {
380 const files = [];
381 let zip = null;
382 try {
383 // Ensure StreamZip is loaded
384 const StreamZipClass = loadStreamZip();
385 zip = new StreamZipClass.async({ file: zipPath });
386 const entries = await zip.entries();
387
388 for (const entry of Object.values(entries)) {
389 if (!entry.isDirectory) {
390 if (isMacOsJunkZipEntry(entry.name)) continue;
391 const ext = path.extname(entry.name).toLowerCase();
392 if (extSet.has(ext)) {
393 if (entry.size <= maxFileSize) {
394 // Use double colon format: zipPath::entryPath
395 const filePath = `${zipPath}::${entry.name}`;
396 // For zip entries, we can't easily calculate hash without extracting
397 // Hash will be calculated later when the file is accessed
398 files.push({
399 filePath: filePath,
400 fileName: entry.name,
401 size: entry.size,
402 mtime: entry.time ? new Date(entry.time) : new Date(),
403 hash: null, // Hash calculated on-demand for zip entries
404 isZipArchive: true,
405 zipEntryPath: entry.name,
406 zip_path: entry.name
407 });
408 }
409 }

Callers 1

processFileFunction · 0.85

Calls 1

loadStreamZipFunction · 0.85

Tested by

no test coverage detected