@ubercode/dcmtk 0.8.0 → 0.8.2

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.d.cts CHANGED
@@ -32,6 +32,8 @@ interface Dcm2xmlOptions extends ToolBaseOptions {
32
32
  readonly writeBinaryData?: boolean | undefined;
33
33
  /** Encode binary data inline instead of referencing external files. Defaults to true when writeBinaryData is true. */
34
34
  readonly encodeBinaryBase64?: boolean | undefined;
35
+ /** Assume the specified character set when SpecificCharacterSet (0008,0005) is absent. Maps to `+Ca`. */
36
+ readonly charsetAssume?: string | undefined;
35
37
  /** Verbosity level for diagnostic output. `'verbose'` maps to `-v`, `'debug'` maps to `-d`. */
36
38
  readonly verbosity?: 'verbose' | 'debug' | undefined;
37
39
  }
@@ -74,6 +76,8 @@ type Dcm2jsonSource = 'xml' | 'direct';
74
76
  interface Dcm2jsonOptions extends ToolBaseOptions {
75
77
  /** Skip the XML primary path and use direct dcm2json only. Defaults to false. */
76
78
  readonly directOnly?: boolean | undefined;
79
+ /** Assume the specified character set when SpecificCharacterSet (0008,0005) is absent. Passed to dcm2xml as `+Ca`. Only effective on the XML path (dcm2json binary does not support this flag). */
80
+ readonly charsetAssume?: string | undefined;
77
81
  /** Verbosity level for diagnostic output. `'verbose'` maps to `-v`, `'debug'` maps to `-d`. */
78
82
  readonly verbosity?: 'verbose' | 'debug' | undefined;
79
83
  }
package/dist/tools.d.ts CHANGED
@@ -32,6 +32,8 @@ interface Dcm2xmlOptions extends ToolBaseOptions {
32
32
  readonly writeBinaryData?: boolean | undefined;
33
33
  /** Encode binary data inline instead of referencing external files. Defaults to true when writeBinaryData is true. */
34
34
  readonly encodeBinaryBase64?: boolean | undefined;
35
+ /** Assume the specified character set when SpecificCharacterSet (0008,0005) is absent. Maps to `+Ca`. */
36
+ readonly charsetAssume?: string | undefined;
35
37
  /** Verbosity level for diagnostic output. `'verbose'` maps to `-v`, `'debug'` maps to `-d`. */
36
38
  readonly verbosity?: 'verbose' | 'debug' | undefined;
37
39
  }
@@ -74,6 +76,8 @@ type Dcm2jsonSource = 'xml' | 'direct';
74
76
  interface Dcm2jsonOptions extends ToolBaseOptions {
75
77
  /** Skip the XML primary path and use direct dcm2json only. Defaults to false. */
76
78
  readonly directOnly?: boolean | undefined;
79
+ /** Assume the specified character set when SpecificCharacterSet (0008,0005) is absent. Passed to dcm2xml as `+Ca`. Only effective on the XML path (dcm2json binary does not support this flag). */
80
+ readonly charsetAssume?: string | undefined;
77
81
  /** Verbosity level for diagnostic output. `'verbose'` maps to `-v`, `'debug'` maps to `-d`. */
78
82
  readonly verbosity?: 'verbose' | 'debug' | undefined;
79
83
  }
package/dist/tools.js CHANGED
@@ -251,6 +251,7 @@ var Dcm2xmlOptionsSchema = z.object({
251
251
  charset: z.enum(["utf8", "latin1", "ascii"]).optional(),
252
252
  writeBinaryData: z.boolean().optional(),
253
253
  encodeBinaryBase64: z.boolean().optional(),
254
+ charsetAssume: z.string().min(1).optional(),
254
255
  verbosity: z.enum(["verbose", "debug"]).optional()
255
256
  }).strict().optional();
256
257
  function pushEncodingArgs(args, options) {
@@ -274,6 +275,9 @@ function buildArgs(inputPath, options) {
274
275
  if (options?.namespace === true) {
275
276
  args.push("+Xn");
276
277
  }
278
+ if (options?.charsetAssume !== void 0) {
279
+ args.push("+Ca", options.charsetAssume);
280
+ }
277
281
  pushEncodingArgs(args, options);
278
282
  args.push(inputPath);
279
283
  return args;
@@ -523,6 +527,7 @@ var Dcm2jsonOptionsSchema = z.object({
523
527
  timeoutMs: z.number().int().positive().optional(),
524
528
  signal: z.instanceof(AbortSignal).optional(),
525
529
  directOnly: z.boolean().optional(),
530
+ charsetAssume: z.string().min(1).optional(),
526
531
  verbosity: z.enum(["verbose", "debug"]).optional()
527
532
  }).strict().optional();
528
533
  var VERBOSITY_FLAGS2 = { verbose: "-v", debug: "-d" };
@@ -532,12 +537,19 @@ function buildVerbosityArgs(verbosity) {
532
537
  }
533
538
  return [];
534
539
  }
535
- async function tryXmlPath(inputPath, timeoutMs, signal, verbosity) {
540
+ function buildXmlOpts(options) {
541
+ const result = {};
542
+ if (options?.verbosity !== void 0) result["verbosity"] = options.verbosity;
543
+ if (options?.charsetAssume !== void 0) result["charsetAssume"] = options.charsetAssume;
544
+ return result;
545
+ }
546
+ async function tryXmlPath(inputPath, timeoutMs, signal, opts) {
536
547
  const xmlBinary = resolveBinary("dcm2xml");
537
548
  if (!xmlBinary.ok) {
538
549
  return err(xmlBinary.error);
539
550
  }
540
- const xmlArgs = [...buildVerbosityArgs(verbosity), "-nat", inputPath];
551
+ const charsetArgs = opts?.charsetAssume !== void 0 ? ["+Ca", opts.charsetAssume] : [];
552
+ const xmlArgs = [...buildVerbosityArgs(opts?.verbosity), ...charsetArgs, "-nat", inputPath];
541
553
  const xmlResult = await execCommand(xmlBinary.value, xmlArgs, { timeoutMs, signal });
542
554
  if (!xmlResult.ok) {
543
555
  return err(xmlResult.error);
@@ -556,7 +568,7 @@ async function tryDirectPath(inputPath, timeoutMs, signal, verbosity) {
556
568
  if (!jsonBinary.ok) {
557
569
  return err(jsonBinary.error);
558
570
  }
559
- const directArgs = [...buildVerbosityArgs(verbosity), inputPath];
571
+ const directArgs = [...buildVerbosityArgs(verbosity), "+b", inputPath];
560
572
  const result = await execCommand(jsonBinary.value, directArgs, { timeoutMs, signal });
561
573
  if (!result.ok) {
562
574
  return err(result.error);
@@ -583,7 +595,7 @@ async function dcm2json(inputPath, options) {
583
595
  if (options?.directOnly === true) {
584
596
  return tryDirectPath(inputPath, timeoutMs, signal, verbosity);
585
597
  }
586
- const xmlResult = await tryXmlPath(inputPath, timeoutMs, signal, verbosity);
598
+ const xmlResult = await tryXmlPath(inputPath, timeoutMs, signal, buildXmlOpts(options));
587
599
  if (xmlResult.ok) {
588
600
  return xmlResult;
589
601
  }