@ubercode/dcmtk 0.12.0 → 0.13.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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DicomTag, a as DicomTagPath } from './DicomInstance-CxLKC-oM.cjs';
2
- export { C as ChangeSet, b as DicomDataset, d as DicomInstance, e as DicomOpenOptions } from './DicomInstance-CxLKC-oM.cjs';
1
+ import { D as DicomTag, a as DicomTagPath } from './DicomInstance-BGXtON9T.cjs';
2
+ export { C as ChangeSet, b as DicomDataset, d as DicomInstance, e as DicomOpenOptions } from './DicomInstance-BGXtON9T.cjs';
3
3
  export { x as xmlToJson } from './dcmodify-Cf-RPHF3.cjs';
4
4
  import './types-Cgumy1N4.cjs';
5
5
 
package/dist/dicom.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DicomTag, a as DicomTagPath } from './DicomInstance-BKUiir0G.js';
2
- export { C as ChangeSet, b as DicomDataset, d as DicomInstance, e as DicomOpenOptions } from './DicomInstance-BKUiir0G.js';
1
+ import { D as DicomTag, a as DicomTagPath } from './DicomInstance-DGWB2mfD.js';
2
+ export { C as ChangeSet, b as DicomDataset, d as DicomInstance, e as DicomOpenOptions } from './DicomInstance-DGWB2mfD.js';
3
3
  export { x as xmlToJson } from './dcmodify-CHvwChFu.js';
4
4
  import './types-Cgumy1N4.js';
5
5
 
package/dist/dicom.js CHANGED
@@ -30720,7 +30720,12 @@ var parser = new XMLParser({
30720
30720
  ignoreAttributes: false,
30721
30721
  attributeNamePrefix: "@_",
30722
30722
  parseTagValue: false,
30723
- isArray: (name) => ARRAY_TAG_NAMES.has(name)
30723
+ isArray: (name) => ARRAY_TAG_NAMES.has(name),
30724
+ // DICOM XML does not use XML entities. Disable entity processing to avoid
30725
+ // the default expansion limit (1000) which rejects files with >1000 tags.
30726
+ // Without this, large studies fall through to dcm2json which hangs on
30727
+ // compressed pixel data (DCMTK bug).
30728
+ processEntities: false
30724
30729
  });
30725
30730
  function xmlToJson(xml) {
30726
30731
  try {
@@ -30781,6 +30786,7 @@ var Dcm2jsonOptionsSchema = z.object({
30781
30786
  signal: z.instanceof(AbortSignal).optional(),
30782
30787
  directOnly: z.boolean().optional(),
30783
30788
  charsetAssume: z.string().min(1).optional(),
30789
+ charsetFallback: z.string().min(1).optional(),
30784
30790
  verbosity: z.enum(["verbose", "debug"]).optional()
30785
30791
  }).strict().optional();
30786
30792
  var VERBOSITY_FLAGS = { verbose: "-v", debug: "-d" };
@@ -30794,27 +30800,34 @@ function buildXmlOpts(options) {
30794
30800
  const result = {};
30795
30801
  if (options?.verbosity !== void 0) result["verbosity"] = options.verbosity;
30796
30802
  if (options?.charsetAssume !== void 0) result["charsetAssume"] = options.charsetAssume;
30803
+ if (options?.charsetFallback !== void 0) result["charsetFallback"] = options.charsetFallback;
30797
30804
  return result;
30798
30805
  }
30806
+ function isCharsetError(stderrOutput) {
30807
+ return stderrOutput.includes("convert character encoding") || stderrOutput.includes("Illegal byte sequence");
30808
+ }
30809
+ async function runXmlAndParse(binary, args, execOpts) {
30810
+ const xmlResult = await execCommand(binary, args, execOpts);
30811
+ if (!xmlResult.ok) return err(xmlResult.error);
30812
+ if (xmlResult.value.exitCode !== 0) {
30813
+ return err(createToolError("dcm2xml", args, xmlResult.value.exitCode, xmlResult.value.stderr));
30814
+ }
30815
+ const jsonResult = xmlToJson(xmlResult.value.stdout);
30816
+ if (!jsonResult.ok) return err(jsonResult.error);
30817
+ return ok({ data: jsonResult.value, source: "xml" });
30818
+ }
30799
30819
  async function tryXmlPath(inputPath, timeoutMs, signal, opts) {
30800
30820
  const xmlBinary = resolveBinary("dcm2xml");
30801
- if (!xmlBinary.ok) {
30802
- return err(xmlBinary.error);
30803
- }
30821
+ if (!xmlBinary.ok) return err(xmlBinary.error);
30804
30822
  const charsetArgs = opts?.charsetAssume !== void 0 ? ["+Ca", opts.charsetAssume] : [];
30805
30823
  const xmlArgs = [...buildVerbosityArgs(opts?.verbosity), ...charsetArgs, "-nat", inputPath];
30806
- const xmlResult = await execCommand(xmlBinary.value, xmlArgs, { timeoutMs, signal });
30807
- if (!xmlResult.ok) {
30808
- return err(xmlResult.error);
30824
+ const execOpts = signal !== void 0 ? { timeoutMs, signal } : { timeoutMs };
30825
+ const result = await runXmlAndParse(xmlBinary.value, xmlArgs, execOpts);
30826
+ if (!result.ok && opts?.charsetFallback !== void 0 && isCharsetError(result.error.message)) {
30827
+ const fallbackArgs = [...buildVerbosityArgs(opts.verbosity), "+Ca", opts.charsetFallback, "-nat", inputPath];
30828
+ return runXmlAndParse(xmlBinary.value, fallbackArgs, execOpts);
30809
30829
  }
30810
- if (xmlResult.value.exitCode !== 0) {
30811
- return err(createToolError("dcm2xml", xmlArgs, xmlResult.value.exitCode, xmlResult.value.stderr));
30812
- }
30813
- const jsonResult = xmlToJson(xmlResult.value.stdout);
30814
- if (!jsonResult.ok) {
30815
- return err(jsonResult.error);
30816
- }
30817
- return ok({ data: jsonResult.value, source: "xml" });
30830
+ return result;
30818
30831
  }
30819
30832
  async function tryDirectPath(inputPath, timeoutMs, signal, verbosity) {
30820
30833
  const jsonBinary = resolveBinary("dcm2json");
@@ -30999,7 +31012,8 @@ var DicomInstance = class _DicomInstance {
30999
31012
  const jsonResult = await dcm2json(path, {
31000
31013
  timeoutMs: options?.timeoutMs ?? DEFAULT_TIMEOUT_MS,
31001
31014
  signal: options?.signal,
31002
- charsetAssume: options?.charsetAssume
31015
+ charsetAssume: options?.charsetAssume,
31016
+ charsetFallback: options?.charsetFallback
31003
31017
  });
31004
31018
  if (!jsonResult.ok) return err(jsonResult.error);
31005
31019
  const datasetResult = DicomDataset.fromJson(jsonResult.value.data);