@ubercode/dcmtk 0.9.0 → 0.9.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.
@@ -1481,6 +1481,7 @@ interface PoolStatus {
1481
1481
  /** Data emitted with FILE_RECEIVED events. */
1482
1482
  interface ReceiverFileData {
1483
1483
  readonly filePath: string;
1484
+ readonly fileSize: number;
1484
1485
  readonly associationId: string;
1485
1486
  readonly associationDir: string;
1486
1487
  readonly callingAE: string;
@@ -1722,6 +1723,8 @@ declare class DicomReceiver extends EventEmitter<DicomReceiverEventMap> {
1722
1723
  private wireFileReceived;
1723
1724
  /** Moves a received file, opens it as DicomInstance, and emits FILE_RECEIVED. */
1724
1725
  private handleFileReceived;
1726
+ /** Inner handler: move file, parse DICOM, emit FILE_RECEIVED or error. */
1727
+ private moveAndEmitFile;
1725
1728
  /** Returns worker to idle pool on association complete, emits summary. */
1726
1729
  private wireAssociationComplete;
1727
1730
  /** Awaits pending file operations, emits ASSOCIATION_COMPLETE, resets worker state. */
@@ -1481,6 +1481,7 @@ interface PoolStatus {
1481
1481
  /** Data emitted with FILE_RECEIVED events. */
1482
1482
  interface ReceiverFileData {
1483
1483
  readonly filePath: string;
1484
+ readonly fileSize: number;
1484
1485
  readonly associationId: string;
1485
1486
  readonly associationDir: string;
1486
1487
  readonly callingAE: string;
@@ -1722,6 +1723,8 @@ declare class DicomReceiver extends EventEmitter<DicomReceiverEventMap> {
1722
1723
  private wireFileReceived;
1723
1724
  /** Moves a received file, opens it as DicomInstance, and emits FILE_RECEIVED. */
1724
1725
  private handleFileReceived;
1726
+ /** Inner handler: move file, parse DICOM, emit FILE_RECEIVED or error. */
1727
+ private moveAndEmitFile;
1725
1728
  /** Returns worker to idle pool on association complete, emits summary. */
1726
1729
  private wireAssociationComplete;
1727
1730
  /** Awaits pending file operations, emits ASSOCIATION_COMPLETE, resets worker state. */
package/dist/index.cjs CHANGED
@@ -36615,7 +36615,7 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
36615
36615
  acseTimeout: this.options.acseTimeout,
36616
36616
  dimseTimeout: this.options.dimseTimeout,
36617
36617
  maxPdu: this.options.maxPdu,
36618
- filenameMode: this.options.filenameMode,
36618
+ filenameMode: this.options.filenameMode ?? "unique",
36619
36619
  filenameExtension: this.options.filenameExtension,
36620
36620
  storageMode: this.options.storageMode
36621
36621
  });
@@ -36724,14 +36724,32 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
36724
36724
  /** Moves a received file, opens it as DicomInstance, and emits FILE_RECEIVED. */
36725
36725
  async handleFileReceived(worker, data) {
36726
36726
  if (worker.associationDir === void 0 || worker.associationId === void 0) return;
36727
- const srcPath = data.filePath;
36728
- const destPath = path__namespace.join(worker.associationDir, path__namespace.basename(srcPath));
36729
36727
  const assocId = worker.associationId;
36730
36728
  const assocDir = worker.associationDir;
36729
+ try {
36730
+ await this.moveAndEmitFile(worker, data, assocId, assocDir);
36731
+ } catch (thrown) {
36732
+ const error = thrown instanceof Error ? thrown : new Error(String(thrown));
36733
+ this.emit("error", {
36734
+ error,
36735
+ filePath: data.filePath,
36736
+ associationId: assocId,
36737
+ associationDir: assocDir,
36738
+ callingAE: data.callingAE,
36739
+ calledAE: data.calledAE,
36740
+ source: data.source
36741
+ });
36742
+ }
36743
+ }
36744
+ /** Inner handler: move file, parse DICOM, emit FILE_RECEIVED or error. */
36745
+ async moveAndEmitFile(worker, data, assocId, assocDir) {
36746
+ const srcPath = data.filePath;
36747
+ const destPath = path__namespace.join(assocDir, path__namespace.basename(srcPath));
36731
36748
  const moveResult = await moveFile(srcPath, destPath);
36732
36749
  const finalPath = moveResult.ok ? destPath : srcPath;
36750
+ const fileSize = await statFileSafe(finalPath);
36733
36751
  worker.files.push(finalPath);
36734
- worker.fileSizes.push(await statFileSafe(finalPath));
36752
+ worker.fileSizes.push(fileSize);
36735
36753
  const openResult = await DicomInstance.open(finalPath);
36736
36754
  if (!openResult.ok) {
36737
36755
  this.emit("error", {
@@ -36747,6 +36765,7 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
36747
36765
  }
36748
36766
  this.emit("FILE_RECEIVED", {
36749
36767
  filePath: finalPath,
36768
+ fileSize,
36750
36769
  associationId: assocId,
36751
36770
  associationDir: assocDir,
36752
36771
  callingAE: data.callingAE,