@ubercode/dcmtk 0.8.2 → 0.9.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.
package/dist/tools.js CHANGED
@@ -3,6 +3,8 @@ import { spawn, execSync } from 'child_process';
3
3
  import kill from 'tree-kill';
4
4
  import { join } from 'path';
5
5
  import { existsSync } from 'fs';
6
+ import { rm, mkdtemp } from 'fs/promises';
7
+ import { tmpdir } from 'os';
6
8
  import { stderr } from 'stderr-lib';
7
9
  import { XMLParser } from 'fast-xml-parser';
8
10
 
@@ -568,13 +570,26 @@ async function tryDirectPath(inputPath, timeoutMs, signal, verbosity) {
568
570
  if (!jsonBinary.ok) {
569
571
  return err(jsonBinary.error);
570
572
  }
571
- const directArgs = [...buildVerbosityArgs(verbosity), "+b", inputPath];
572
- const result = await execCommand(jsonBinary.value, directArgs, { timeoutMs, signal });
573
+ const bulkDir = await createBulkTempDir();
574
+ const directArgs = [...buildVerbosityArgs(verbosity), "+b", "+bd", bulkDir, inputPath];
575
+ try {
576
+ const execOpts = signal !== void 0 ? { timeoutMs, signal } : { timeoutMs };
577
+ return await execAndParse(jsonBinary.value, directArgs, inputPath, execOpts);
578
+ } finally {
579
+ rm(bulkDir, { recursive: true, force: true }).catch(() => {
580
+ });
581
+ }
582
+ }
583
+ async function createBulkTempDir() {
584
+ return mkdtemp(join(tmpdir(), "dcm2json-bulk-"));
585
+ }
586
+ async function execAndParse(binary, args, inputPath, execOpts) {
587
+ const result = await execCommand(binary, args, execOpts);
573
588
  if (!result.ok) {
574
589
  return err(result.error);
575
590
  }
576
591
  if (result.value.exitCode !== 0) {
577
- return err(createToolError("dcm2json", directArgs, result.value.exitCode, result.value.stderr));
592
+ return err(createToolError("dcm2json", args, result.value.exitCode, result.value.stderr));
578
593
  }
579
594
  try {
580
595
  const repaired = repairJson(result.value.stdout);