@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/dicom.js CHANGED
@@ -3,9 +3,10 @@ import { stderr, tryCatch } from 'stderr-lib';
3
3
  import { spawn, execSync } from 'child_process';
4
4
  import kill from 'tree-kill';
5
5
  import { existsSync } from 'fs';
6
+ import { copyFile, unlink, stat, rm, mkdtemp } from 'fs/promises';
7
+ import { tmpdir } from 'os';
6
8
  import { z } from 'zod';
7
9
  import { XMLParser } from 'fast-xml-parser';
8
- import { copyFile, unlink, stat } from 'fs/promises';
9
10
 
10
11
  var __defProp = Object.defineProperty;
11
12
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -30819,13 +30820,26 @@ async function tryDirectPath(inputPath, timeoutMs, signal, verbosity) {
30819
30820
  if (!jsonBinary.ok) {
30820
30821
  return err(jsonBinary.error);
30821
30822
  }
30822
- const directArgs = [...buildVerbosityArgs(verbosity), "+b", inputPath];
30823
- const result = await execCommand(jsonBinary.value, directArgs, { timeoutMs, signal });
30823
+ const bulkDir = await createBulkTempDir();
30824
+ const directArgs = [...buildVerbosityArgs(verbosity), "+b", "+bd", bulkDir, inputPath];
30825
+ try {
30826
+ const execOpts = signal !== void 0 ? { timeoutMs, signal } : { timeoutMs };
30827
+ return await execAndParse(jsonBinary.value, directArgs, inputPath, execOpts);
30828
+ } finally {
30829
+ rm(bulkDir, { recursive: true, force: true }).catch(() => {
30830
+ });
30831
+ }
30832
+ }
30833
+ async function createBulkTempDir() {
30834
+ return mkdtemp(join(tmpdir(), "dcm2json-bulk-"));
30835
+ }
30836
+ async function execAndParse(binary, args, inputPath, execOpts) {
30837
+ const result = await execCommand(binary, args, execOpts);
30824
30838
  if (!result.ok) {
30825
30839
  return err(result.error);
30826
30840
  }
30827
30841
  if (result.value.exitCode !== 0) {
30828
- return err(createToolError("dcm2json", directArgs, result.value.exitCode, result.value.stderr));
30842
+ return err(createToolError("dcm2json", args, result.value.exitCode, result.value.stderr));
30829
30843
  }
30830
30844
  try {
30831
30845
  const repaired = repairJson(result.value.stdout);