Skip to content

Commit 1182aa9

Browse files
Fix DICOM file storage to include preamble (#13)
Use enforce_file_format=True with dcmwrite() to ensure the 128-byte preamble and 'DICM' prefix are written. Without this, stored files were invalid DICOM files that Manage couldn't read.
1 parent 22a4955 commit 1182aa9

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/services/dicom/c_store.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from io import BytesIO
33

44
from pydicom import Dataset, dcmwrite
5-
from pydicom.filebase import DicomFileLike
65
from pynetdicom.events import Event
76
from pynetdicom.sop_class import (
87
DigitalMammographyXRayImageStorageForPresentation, # type: ignore
@@ -72,10 +71,9 @@ def call(self, event: Event) -> int:
7271
logger.error(e, exc_info=True)
7372
return FAILURE
7473

75-
# https://pydicom.github.io/pydicom/stable/auto_examples/memory_dataset.html
7674
def dataset_to_bytes(self, ds: Dataset) -> bytes:
7775
with BytesIO() as buffer:
78-
memory_dataset = DicomFileLike(buffer)
79-
dcmwrite(memory_dataset, ds)
80-
memory_dataset.seek(0)
81-
return memory_dataset.read()
76+
# enforce_file_format=True ensures the 128-byte preamble and 'DICM' prefix are written
77+
dcmwrite(buffer, ds, enforce_file_format=True)
78+
buffer.seek(0)
79+
return buffer.read()

0 commit comments

Comments
 (0)