dicom-curate 0.32.1 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37140,11 +37140,8 @@ var keepScanning = true;
37140
37140
  var pauseResolve = null;
37141
37141
  var pausePromise = null;
37142
37142
  var totalDiscovered = 0;
37143
- var countingMode = false;
37144
- var fileBuffer = [];
37145
37143
  function pauseScanning() {
37146
37144
  if (!pausePromise) {
37147
- countingMode = true;
37148
37145
  pausePromise = new Promise((resolve) => {
37149
37146
  pauseResolve = resolve;
37150
37147
  });
@@ -37152,7 +37149,6 @@ function pauseScanning() {
37152
37149
  }
37153
37150
  function resumeScanning() {
37154
37151
  if (pauseResolve) {
37155
- countingMode = false;
37156
37152
  pauseResolve();
37157
37153
  pauseResolve = null;
37158
37154
  pausePromise = null;
@@ -37286,7 +37282,7 @@ async function shouldProcessFileNode(filePath, fileName, fileSize, fileAnomalies
37286
37282
  return true;
37287
37283
  }
37288
37284
  }
37289
- function cheapFilter(fileName, fileSize, filePath) {
37285
+ function cheapFilterNameOnly(fileName, filePath) {
37290
37286
  const allExcludedFiletypes = [
37291
37287
  ...noDefaultExclusions ? [] : DEFAULT_EXCLUDED_FILETYPES,
37292
37288
  ...excludedFiletypes
@@ -37299,100 +37295,8 @@ function cheapFilter(fileName, fileSize, filePath) {
37299
37295
  )) {
37300
37296
  return false;
37301
37297
  }
37302
- if (noDicomSignatureCheck) {
37303
- return true;
37304
- }
37305
- if (fileSize < 132) {
37306
- return false;
37307
- }
37308
37298
  return true;
37309
37299
  }
37310
- async function drainBuffer() {
37311
- while (fileBuffer.length > 0 && keepScanning) {
37312
- const item = fileBuffer.shift();
37313
- const fileAnomalies = [];
37314
- if (item.kind === "handle") {
37315
- const filePath = `${item.prefix}/${item.name}`;
37316
- if (await shouldProcessFile(item.file, fileAnomalies, filePath)) {
37317
- globalThis.postMessage({
37318
- response: "file",
37319
- fileInfo: {
37320
- path: item.prefix,
37321
- name: item.name,
37322
- size: item.size,
37323
- kind: "handle",
37324
- fileHandle: item.entry
37325
- },
37326
- previousFileInfo: item.prev
37327
- });
37328
- } else {
37329
- totalDiscovered--;
37330
- globalThis.postMessage({
37331
- response: "count",
37332
- totalDiscovered
37333
- });
37334
- if (fileAnomalies.length > 0) {
37335
- globalThis.postMessage({
37336
- response: "scanAnomalies",
37337
- fileInfo: {
37338
- path: item.prefix,
37339
- name: item.name,
37340
- size: item.size,
37341
- kind: "handle",
37342
- fileHandle: item.entry
37343
- },
37344
- anomalies: fileAnomalies,
37345
- previousFileInfo: item.prev
37346
- });
37347
- }
37348
- }
37349
- } else {
37350
- if (await shouldProcessFileNode(
37351
- item.filePath,
37352
- item.name,
37353
- item.size,
37354
- fileAnomalies,
37355
- `${item.prefix}/${item.name}`
37356
- )) {
37357
- globalThis.postMessage({
37358
- response: "file",
37359
- fileInfo: {
37360
- path: item.prefix,
37361
- name: item.name,
37362
- size: item.size,
37363
- kind: "path",
37364
- fullPath: item.filePath
37365
- },
37366
- previousFileInfo: item.prev
37367
- });
37368
- } else {
37369
- totalDiscovered--;
37370
- globalThis.postMessage({
37371
- response: "count",
37372
- totalDiscovered
37373
- });
37374
- if (fileAnomalies.length > 0) {
37375
- globalThis.postMessage({
37376
- response: "scanAnomalies",
37377
- fileInfo: {
37378
- path: item.prefix,
37379
- name: item.name,
37380
- size: item.size,
37381
- kind: "path",
37382
- fullPath: item.filePath
37383
- },
37384
- anomalies: fileAnomalies,
37385
- previousFileInfo: item.prev
37386
- });
37387
- }
37388
- }
37389
- }
37390
- if (!await waitIfPaused())
37391
- return;
37392
- if (countingMode)
37393
- return;
37394
- }
37395
- }
37396
37300
  fixupNodeWorkerEnvironment().then(() => {
37397
37301
  globalThis.addEventListener("message", (event) => {
37398
37302
  switch (event.data.request) {
@@ -37417,8 +37321,6 @@ fixupNodeWorkerEnvironment().then(() => {
37417
37321
  noDefaultExclusions = event.data.noDefaultExclusions ?? false;
37418
37322
  keepScanning = true;
37419
37323
  totalDiscovered = 0;
37420
- countingMode = false;
37421
- fileBuffer.length = 0;
37422
37324
  if ("path" in eventData) {
37423
37325
  scanDirectoryNode(eventData.path);
37424
37326
  } else if ("directoryHandle" in eventData) {
@@ -37496,8 +37398,16 @@ async function scanS3Bucket(bucketOptions) {
37496
37398
  }
37497
37399
  }
37498
37400
  }
37401
+ globalThis.postMessage({
37402
+ response: "count",
37403
+ totalDiscovered
37404
+ });
37499
37405
  continuationToken = data2.NextContinuationToken;
37500
37406
  } while (continuationToken);
37407
+ globalThis.postMessage({
37408
+ response: "count",
37409
+ totalDiscovered
37410
+ });
37501
37411
  globalThis.postMessage({ response: "done" });
37502
37412
  } catch (error2) {
37503
37413
  globalThis.postMessage({
@@ -37509,58 +37419,37 @@ async function scanS3Bucket(bucketOptions) {
37509
37419
  }
37510
37420
  }
37511
37421
  async function scanDirectory(dir) {
37512
- async function traverse(dir2, prefix) {
37513
- for await (const entry of dir2.values()) {
37422
+ async function counter(dirHandle, prefix) {
37423
+ for await (const entry of dirHandle.values()) {
37424
+ if (!keepScanning)
37425
+ return;
37426
+ if (entry.kind === "file") {
37427
+ const key = `${prefix}/${entry.name}`;
37428
+ if (cheapFilterNameOnly(entry.name, key)) {
37429
+ totalDiscovered++;
37430
+ globalThis.postMessage({
37431
+ response: "count",
37432
+ totalDiscovered
37433
+ });
37434
+ }
37435
+ } else if (entry.kind === "directory") {
37436
+ await counter(
37437
+ entry,
37438
+ prefix + "/" + entry.name
37439
+ );
37440
+ }
37441
+ }
37442
+ }
37443
+ async function feeder(dirHandle, prefix) {
37444
+ for await (const entry of dirHandle.values()) {
37514
37445
  if (!keepScanning)
37515
37446
  return;
37516
37447
  if (entry.kind === "file") {
37517
37448
  const file = await entry.getFile();
37518
37449
  const key = `${prefix}/${entry.name}`;
37519
37450
  const prev = previousIndex ? previousIndex[key] : void 0;
37520
- if (countingMode) {
37521
- if (cheapFilter(entry.name, file.size, key)) {
37522
- totalDiscovered++;
37523
- fileBuffer.push({
37524
- kind: "handle",
37525
- entry,
37526
- file,
37527
- prefix,
37528
- name: entry.name,
37529
- size: file.size,
37530
- prev
37531
- });
37532
- globalThis.postMessage({
37533
- response: "count",
37534
- totalDiscovered
37535
- });
37536
- }
37537
- continue;
37538
- }
37539
- if (fileBuffer.length > 0) {
37540
- await drainBuffer();
37541
- if (countingMode) {
37542
- if (cheapFilter(entry.name, file.size, key)) {
37543
- totalDiscovered++;
37544
- fileBuffer.push({
37545
- kind: "handle",
37546
- entry,
37547
- file,
37548
- prefix,
37549
- name: entry.name,
37550
- size: file.size,
37551
- prev
37552
- });
37553
- globalThis.postMessage({
37554
- response: "count",
37555
- totalDiscovered
37556
- });
37557
- }
37558
- continue;
37559
- }
37560
- }
37561
37451
  const fileAnomalies = [];
37562
37452
  if (await shouldProcessFile(file, fileAnomalies, key)) {
37563
- totalDiscovered++;
37564
37453
  globalThis.postMessage({
37565
37454
  response: "file",
37566
37455
  fileInfo: {
@@ -37572,30 +37461,33 @@ async function scanDirectory(dir) {
37572
37461
  },
37573
37462
  previousFileInfo: prev
37574
37463
  });
37575
- if (totalDiscovered % 100 === 0) {
37464
+ } else {
37465
+ if (cheapFilterNameOnly(entry.name, key)) {
37466
+ totalDiscovered--;
37576
37467
  globalThis.postMessage({
37577
37468
  response: "count",
37578
37469
  totalDiscovered
37579
37470
  });
37580
37471
  }
37581
- } else if (fileAnomalies.length > 0) {
37582
- globalThis.postMessage({
37583
- response: "scanAnomalies",
37584
- fileInfo: {
37585
- path: prefix,
37586
- name: entry.name,
37587
- size: file.size,
37588
- kind: "handle",
37589
- fileHandle: entry
37590
- },
37591
- anomalies: fileAnomalies,
37592
- previousFileInfo: prev
37593
- });
37472
+ if (fileAnomalies.length > 0) {
37473
+ globalThis.postMessage({
37474
+ response: "scanAnomalies",
37475
+ fileInfo: {
37476
+ path: prefix,
37477
+ name: entry.name,
37478
+ size: file.size,
37479
+ kind: "handle",
37480
+ fileHandle: entry
37481
+ },
37482
+ anomalies: fileAnomalies,
37483
+ previousFileInfo: prev
37484
+ });
37485
+ }
37594
37486
  }
37595
37487
  if (!await waitIfPaused())
37596
37488
  return;
37597
37489
  } else if (entry.kind === "directory") {
37598
- await traverse(
37490
+ await feeder(
37599
37491
  entry,
37600
37492
  prefix + "/" + entry.name
37601
37493
  );
@@ -37603,11 +37495,7 @@ async function scanDirectory(dir) {
37603
37495
  }
37604
37496
  }
37605
37497
  try {
37606
- await traverse(dir, dir.name);
37607
- if (fileBuffer.length > 0) {
37608
- countingMode = false;
37609
- await drainBuffer();
37610
- }
37498
+ await Promise.all([counter(dir, dir.name), feeder(dir, dir.name)]);
37611
37499
  globalThis.postMessage({
37612
37500
  response: "count",
37613
37501
  totalDiscovered
@@ -37626,7 +37514,30 @@ async function scanDirectoryNode(dirPath) {
37626
37514
  try {
37627
37515
  const fs = await import("fs/promises");
37628
37516
  const path = await import("path");
37629
- async function traverse(currentPath, prefix) {
37517
+ async function counter(currentPath, prefix) {
37518
+ const entries = await fs.readdir(currentPath, { withFileTypes: true });
37519
+ entries.sort((a4, b4) => a4.name.localeCompare(b4.name));
37520
+ for (const entry of entries) {
37521
+ if (!keepScanning)
37522
+ return;
37523
+ if (entry.isFile()) {
37524
+ const key = `${prefix}/${entry.name}`;
37525
+ if (cheapFilterNameOnly(entry.name, key)) {
37526
+ totalDiscovered++;
37527
+ globalThis.postMessage({
37528
+ response: "count",
37529
+ totalDiscovered
37530
+ });
37531
+ }
37532
+ } else if (entry.isDirectory()) {
37533
+ await counter(
37534
+ path.join(currentPath, entry.name),
37535
+ prefix + "/" + entry.name
37536
+ );
37537
+ }
37538
+ }
37539
+ }
37540
+ async function feeder(currentPath, prefix) {
37630
37541
  const entries = await fs.readdir(currentPath, { withFileTypes: true });
37631
37542
  entries.sort((a4, b4) => a4.name.localeCompare(b4.name));
37632
37543
  for (const entry of entries) {
@@ -37637,45 +37548,6 @@ async function scanDirectoryNode(dirPath) {
37637
37548
  const stats = await fs.stat(filePath);
37638
37549
  const key = `${prefix}/${entry.name}`;
37639
37550
  const prev = previousIndex ? previousIndex[key] : void 0;
37640
- if (countingMode) {
37641
- if (cheapFilter(entry.name, stats.size, key)) {
37642
- totalDiscovered++;
37643
- fileBuffer.push({
37644
- kind: "path",
37645
- filePath,
37646
- name: entry.name,
37647
- size: stats.size,
37648
- prefix,
37649
- prev
37650
- });
37651
- globalThis.postMessage({
37652
- response: "count",
37653
- totalDiscovered
37654
- });
37655
- }
37656
- continue;
37657
- }
37658
- if (fileBuffer.length > 0) {
37659
- await drainBuffer();
37660
- if (countingMode) {
37661
- if (cheapFilter(entry.name, stats.size, key)) {
37662
- totalDiscovered++;
37663
- fileBuffer.push({
37664
- kind: "path",
37665
- filePath,
37666
- name: entry.name,
37667
- size: stats.size,
37668
- prefix,
37669
- prev
37670
- });
37671
- globalThis.postMessage({
37672
- response: "count",
37673
- totalDiscovered
37674
- });
37675
- }
37676
- continue;
37677
- }
37678
- }
37679
37551
  const fileAnomalies = [];
37680
37552
  if (await shouldProcessFileNode(
37681
37553
  filePath,
@@ -37684,7 +37556,6 @@ async function scanDirectoryNode(dirPath) {
37684
37556
  fileAnomalies,
37685
37557
  key
37686
37558
  )) {
37687
- totalDiscovered++;
37688
37559
  globalThis.postMessage({
37689
37560
  response: "file",
37690
37561
  fileInfo: {
@@ -37696,42 +37567,41 @@ async function scanDirectoryNode(dirPath) {
37696
37567
  },
37697
37568
  previousFileInfo: prev
37698
37569
  });
37699
- if (totalDiscovered % 100 === 0) {
37570
+ } else {
37571
+ if (cheapFilterNameOnly(entry.name, key)) {
37572
+ totalDiscovered--;
37700
37573
  globalThis.postMessage({
37701
37574
  response: "count",
37702
37575
  totalDiscovered
37703
37576
  });
37704
37577
  }
37705
- } else if (fileAnomalies.length > 0) {
37706
- globalThis.postMessage({
37707
- response: "scanAnomalies",
37708
- fileInfo: {
37709
- path: prefix,
37710
- name: entry.name,
37711
- size: stats.size,
37712
- kind: "path",
37713
- fullPath: filePath
37714
- },
37715
- anomalies: fileAnomalies,
37716
- previousFileInfo: prev
37717
- });
37578
+ if (fileAnomalies.length > 0) {
37579
+ globalThis.postMessage({
37580
+ response: "scanAnomalies",
37581
+ fileInfo: {
37582
+ path: prefix,
37583
+ name: entry.name,
37584
+ size: stats.size,
37585
+ kind: "path",
37586
+ fullPath: filePath
37587
+ },
37588
+ anomalies: fileAnomalies,
37589
+ previousFileInfo: prev
37590
+ });
37591
+ }
37718
37592
  }
37719
37593
  if (!await waitIfPaused())
37720
37594
  return;
37721
37595
  } else if (entry.isDirectory()) {
37722
- await traverse(
37596
+ await feeder(
37723
37597
  path.join(currentPath, entry.name),
37724
37598
  prefix + "/" + entry.name
37725
37599
  );
37726
37600
  }
37727
37601
  }
37728
37602
  }
37729
- const dirName = await import("path").then((p4) => p4.basename(dirPath));
37730
- await traverse(dirPath, dirName);
37731
- if (fileBuffer.length > 0) {
37732
- countingMode = false;
37733
- await drainBuffer();
37734
- }
37603
+ const dirName = path.basename(dirPath);
37604
+ await Promise.all([counter(dirPath, dirName), feeder(dirPath, dirName)]);
37735
37605
  globalThis.postMessage({
37736
37606
  response: "count",
37737
37607
  totalDiscovered