@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.
@@ -458,6 +458,11 @@ interface FileIOOptions {
458
458
  /** AbortSignal for external cancellation. */
459
459
  readonly signal?: AbortSignal | undefined;
460
460
  }
461
+ /** Options for opening a DICOM file. Extends FileIOOptions with read-specific settings. */
462
+ interface DicomOpenOptions extends FileIOOptions {
463
+ /** Assume the specified character set when SpecificCharacterSet (0008,0005) is absent. Maps to dcm2xml `+Ca`. */
464
+ readonly charsetAssume?: string | undefined;
465
+ }
461
466
 
462
467
  /**
463
468
  * Unified DICOM object composing DicomDataset + ChangeSet + file I/O.
@@ -497,10 +502,10 @@ declare class DicomInstance {
497
502
  * Opens a DICOM file and creates a DicomInstance.
498
503
  *
499
504
  * @param path - Filesystem path to the DICOM file
500
- * @param options - Timeout and abort options
505
+ * @param options - Timeout, abort, and charset options
501
506
  * @returns A Result containing the DicomInstance or an error
502
507
  */
503
- static open(path: string, options?: FileIOOptions): Promise<Result<DicomInstance>>;
508
+ static open(path: string, options?: DicomOpenOptions): Promise<Result<DicomInstance>>;
504
509
  /**
505
510
  * Creates a DicomInstance from an existing DicomDataset.
506
511
  *
@@ -670,4 +675,4 @@ declare class DicomInstance {
670
675
  getMetadata(key: string): unknown;
671
676
  }
672
677
 
673
- export { type AETitle as A, type Brand as B, ChangeSet as C, type DicomTag as D, type Port as P, type SOPClassUID as S, type TransferSyntaxUID as T, type WalkTagEntry as W, type DicomTagPath as a, DicomDataset as b, type DicomFilePath as c, DicomInstance as d, type WalkTagsOptions as e, createAETitle as f, createDicomFilePath as g, createDicomTag as h, createDicomTagPath as i, createPort as j, createSOPClassUID as k, createTransferSyntaxUID as l, tag as t, walkTags as w };
678
+ export { type AETitle as A, type Brand as B, ChangeSet as C, type DicomTag as D, type Port as P, type SOPClassUID as S, type TransferSyntaxUID as T, type WalkTagEntry as W, type DicomTagPath as a, DicomDataset as b, type DicomFilePath as c, DicomInstance as d, type DicomOpenOptions as e, type WalkTagsOptions as f, createAETitle as g, createDicomFilePath as h, createDicomTag as i, createDicomTagPath as j, createPort as k, createSOPClassUID as l, createTransferSyntaxUID as m, tag as t, walkTags as w };
@@ -458,6 +458,11 @@ interface FileIOOptions {
458
458
  /** AbortSignal for external cancellation. */
459
459
  readonly signal?: AbortSignal | undefined;
460
460
  }
461
+ /** Options for opening a DICOM file. Extends FileIOOptions with read-specific settings. */
462
+ interface DicomOpenOptions extends FileIOOptions {
463
+ /** Assume the specified character set when SpecificCharacterSet (0008,0005) is absent. Maps to dcm2xml `+Ca`. */
464
+ readonly charsetAssume?: string | undefined;
465
+ }
461
466
 
462
467
  /**
463
468
  * Unified DICOM object composing DicomDataset + ChangeSet + file I/O.
@@ -497,10 +502,10 @@ declare class DicomInstance {
497
502
  * Opens a DICOM file and creates a DicomInstance.
498
503
  *
499
504
  * @param path - Filesystem path to the DICOM file
500
- * @param options - Timeout and abort options
505
+ * @param options - Timeout, abort, and charset options
501
506
  * @returns A Result containing the DicomInstance or an error
502
507
  */
503
- static open(path: string, options?: FileIOOptions): Promise<Result<DicomInstance>>;
508
+ static open(path: string, options?: DicomOpenOptions): Promise<Result<DicomInstance>>;
504
509
  /**
505
510
  * Creates a DicomInstance from an existing DicomDataset.
506
511
  *
@@ -670,4 +675,4 @@ declare class DicomInstance {
670
675
  getMetadata(key: string): unknown;
671
676
  }
672
677
 
673
- export { type AETitle as A, type Brand as B, ChangeSet as C, type DicomTag as D, type Port as P, type SOPClassUID as S, type TransferSyntaxUID as T, type WalkTagEntry as W, type DicomTagPath as a, DicomDataset as b, type DicomFilePath as c, DicomInstance as d, type WalkTagsOptions as e, createAETitle as f, createDicomFilePath as g, createDicomTag as h, createDicomTagPath as i, createPort as j, createSOPClassUID as k, createTransferSyntaxUID as l, tag as t, walkTags as w };
678
+ export { type AETitle as A, type Brand as B, ChangeSet as C, type DicomTag as D, type Port as P, type SOPClassUID as S, type TransferSyntaxUID as T, type WalkTagEntry as W, type DicomTagPath as a, DicomDataset as b, type DicomFilePath as c, DicomInstance as d, type DicomOpenOptions as e, type WalkTagsOptions as f, createAETitle as g, createDicomFilePath as h, createDicomTag as i, createDicomTagPath as j, createPort as k, createSOPClassUID as l, createTransferSyntaxUID as m, tag as t, walkTags as w };
package/dist/dicom.cjs CHANGED
@@ -30784,6 +30784,7 @@ var Dcm2jsonOptionsSchema = zod.z.object({
30784
30784
  timeoutMs: zod.z.number().int().positive().optional(),
30785
30785
  signal: zod.z.instanceof(AbortSignal).optional(),
30786
30786
  directOnly: zod.z.boolean().optional(),
30787
+ charsetAssume: zod.z.string().min(1).optional(),
30787
30788
  verbosity: zod.z.enum(["verbose", "debug"]).optional()
30788
30789
  }).strict().optional();
30789
30790
  var VERBOSITY_FLAGS = { verbose: "-v", debug: "-d" };
@@ -30793,12 +30794,19 @@ function buildVerbosityArgs(verbosity) {
30793
30794
  }
30794
30795
  return [];
30795
30796
  }
30796
- async function tryXmlPath(inputPath, timeoutMs, signal, verbosity) {
30797
+ function buildXmlOpts(options) {
30798
+ const result = {};
30799
+ if (options?.verbosity !== void 0) result["verbosity"] = options.verbosity;
30800
+ if (options?.charsetAssume !== void 0) result["charsetAssume"] = options.charsetAssume;
30801
+ return result;
30802
+ }
30803
+ async function tryXmlPath(inputPath, timeoutMs, signal, opts) {
30797
30804
  const xmlBinary = resolveBinary("dcm2xml");
30798
30805
  if (!xmlBinary.ok) {
30799
30806
  return err(xmlBinary.error);
30800
30807
  }
30801
- const xmlArgs = [...buildVerbosityArgs(verbosity), "-nat", inputPath];
30808
+ const charsetArgs = opts?.charsetAssume !== void 0 ? ["+Ca", opts.charsetAssume] : [];
30809
+ const xmlArgs = [...buildVerbosityArgs(opts?.verbosity), ...charsetArgs, "-nat", inputPath];
30802
30810
  const xmlResult = await execCommand(xmlBinary.value, xmlArgs, { timeoutMs, signal });
30803
30811
  if (!xmlResult.ok) {
30804
30812
  return err(xmlResult.error);
@@ -30817,7 +30825,7 @@ async function tryDirectPath(inputPath, timeoutMs, signal, verbosity) {
30817
30825
  if (!jsonBinary.ok) {
30818
30826
  return err(jsonBinary.error);
30819
30827
  }
30820
- const directArgs = [...buildVerbosityArgs(verbosity), inputPath];
30828
+ const directArgs = [...buildVerbosityArgs(verbosity), "+b", inputPath];
30821
30829
  const result = await execCommand(jsonBinary.value, directArgs, { timeoutMs, signal });
30822
30830
  if (!result.ok) {
30823
30831
  return err(result.error);
@@ -30844,7 +30852,7 @@ async function dcm2json(inputPath, options) {
30844
30852
  if (options?.directOnly === true) {
30845
30853
  return tryDirectPath(inputPath, timeoutMs, signal, verbosity);
30846
30854
  }
30847
- const xmlResult = await tryXmlPath(inputPath, timeoutMs, signal, verbosity);
30855
+ const xmlResult = await tryXmlPath(inputPath, timeoutMs, signal, buildXmlOpts(options));
30848
30856
  if (xmlResult.ok) {
30849
30857
  return xmlResult;
30850
30858
  }
@@ -30973,7 +30981,7 @@ var DicomInstance = class _DicomInstance {
30973
30981
  * Opens a DICOM file and creates a DicomInstance.
30974
30982
  *
30975
30983
  * @param path - Filesystem path to the DICOM file
30976
- * @param options - Timeout and abort options
30984
+ * @param options - Timeout, abort, and charset options
30977
30985
  * @returns A Result containing the DicomInstance or an error
30978
30986
  */
30979
30987
  static async open(path, options) {
@@ -30981,7 +30989,8 @@ var DicomInstance = class _DicomInstance {
30981
30989
  if (!filePathResult.ok) return err(filePathResult.error);
30982
30990
  const jsonResult = await dcm2json(path, {
30983
30991
  timeoutMs: options?.timeoutMs ?? DEFAULT_TIMEOUT_MS,
30984
- signal: options?.signal
30992
+ signal: options?.signal,
30993
+ charsetAssume: options?.charsetAssume
30985
30994
  });
30986
30995
  if (!jsonResult.ok) return err(jsonResult.error);
30987
30996
  const datasetResult = DicomDataset.fromJson(jsonResult.value.data);