@ubercode/dcmtk 0.12.1 → 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
@@ -30786,6 +30786,7 @@ var Dcm2jsonOptionsSchema = z.object({
30786
30786
  signal: z.instanceof(AbortSignal).optional(),
30787
30787
  directOnly: z.boolean().optional(),
30788
30788
  charsetAssume: z.string().min(1).optional(),
30789
+ charsetFallback: z.string().min(1).optional(),
30789
30790
  verbosity: z.enum(["verbose", "debug"]).optional()
30790
30791
  }).strict().optional();
30791
30792
  var VERBOSITY_FLAGS = { verbose: "-v", debug: "-d" };
@@ -30799,27 +30800,34 @@ function buildXmlOpts(options) {
30799
30800
  const result = {};
30800
30801
  if (options?.verbosity !== void 0) result["verbosity"] = options.verbosity;
30801
30802
  if (options?.charsetAssume !== void 0) result["charsetAssume"] = options.charsetAssume;
30803
+ if (options?.charsetFallback !== void 0) result["charsetFallback"] = options.charsetFallback;
30802
30804
  return result;
30803
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
+ }
30804
30819
  async function tryXmlPath(inputPath, timeoutMs, signal, opts) {
30805
30820
  const xmlBinary = resolveBinary("dcm2xml");
30806
- if (!xmlBinary.ok) {
30807
- return err(xmlBinary.error);
30808
- }
30821
+ if (!xmlBinary.ok) return err(xmlBinary.error);
30809
30822
  const charsetArgs = opts?.charsetAssume !== void 0 ? ["+Ca", opts.charsetAssume] : [];
30810
30823
  const xmlArgs = [...buildVerbosityArgs(opts?.verbosity), ...charsetArgs, "-nat", inputPath];
30811
- const xmlResult = await execCommand(xmlBinary.value, xmlArgs, { timeoutMs, signal });
30812
- if (!xmlResult.ok) {
30813
- 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);
30814
30829
  }
30815
- if (xmlResult.value.exitCode !== 0) {
30816
- return err(createToolError("dcm2xml", xmlArgs, xmlResult.value.exitCode, xmlResult.value.stderr));
30817
- }
30818
- const jsonResult = xmlToJson(xmlResult.value.stdout);
30819
- if (!jsonResult.ok) {
30820
- return err(jsonResult.error);
30821
- }
30822
- return ok({ data: jsonResult.value, source: "xml" });
30830
+ return result;
30823
30831
  }
30824
30832
  async function tryDirectPath(inputPath, timeoutMs, signal, verbosity) {
30825
30833
  const jsonBinary = resolveBinary("dcm2json");
@@ -31004,7 +31012,8 @@ var DicomInstance = class _DicomInstance {
31004
31012
  const jsonResult = await dcm2json(path, {
31005
31013
  timeoutMs: options?.timeoutMs ?? DEFAULT_TIMEOUT_MS,
31006
31014
  signal: options?.signal,
31007
- charsetAssume: options?.charsetAssume
31015
+ charsetAssume: options?.charsetAssume,
31016
+ charsetFallback: options?.charsetFallback
31008
31017
  });
31009
31018
  if (!jsonResult.ok) return err(jsonResult.error);
31010
31019
  const datasetResult = DicomDataset.fromJson(jsonResult.value.data);