@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.cjs CHANGED
@@ -5,6 +5,8 @@ var child_process = require('child_process');
5
5
  var kill = require('tree-kill');
6
6
  var path = require('path');
7
7
  var fs = require('fs');
8
+ var promises = require('fs/promises');
9
+ var os = require('os');
8
10
  var stderrLib = require('stderr-lib');
9
11
  var fastXmlParser = require('fast-xml-parser');
10
12
 
@@ -574,13 +576,26 @@ async function tryDirectPath(inputPath, timeoutMs, signal, verbosity) {
574
576
  if (!jsonBinary.ok) {
575
577
  return err(jsonBinary.error);
576
578
  }
577
- const directArgs = [...buildVerbosityArgs(verbosity), "+b", inputPath];
578
- const result = await execCommand(jsonBinary.value, directArgs, { timeoutMs, signal });
579
+ const bulkDir = await createBulkTempDir();
580
+ const directArgs = [...buildVerbosityArgs(verbosity), "+b", "+bd", bulkDir, inputPath];
581
+ try {
582
+ const execOpts = signal !== void 0 ? { timeoutMs, signal } : { timeoutMs };
583
+ return await execAndParse(jsonBinary.value, directArgs, inputPath, execOpts);
584
+ } finally {
585
+ promises.rm(bulkDir, { recursive: true, force: true }).catch(() => {
586
+ });
587
+ }
588
+ }
589
+ async function createBulkTempDir() {
590
+ return promises.mkdtemp(path.join(os.tmpdir(), "dcm2json-bulk-"));
591
+ }
592
+ async function execAndParse(binary, args, inputPath, execOpts) {
593
+ const result = await execCommand(binary, args, execOpts);
579
594
  if (!result.ok) {
580
595
  return err(result.error);
581
596
  }
582
597
  if (result.value.exitCode !== 0) {
583
- return err(createToolError("dcm2json", directArgs, result.value.exitCode, result.value.stderr));
598
+ return err(createToolError("dcm2json", args, result.value.exitCode, result.value.stderr));
584
599
  }
585
600
  try {
586
601
  const repaired = repairJson(result.value.stdout);