- pydicom.filereader.read_preamble(fp: BinaryIO, force: bool) bytes | None ¶
Return the 128-byte DICOM preamble in fp if present.
fp should be positioned at the start of the file-like. If the preamble and prefix are found then after reading fp will be positioned at the first byte after the prefix (byte offset 133). If either the preamble or prefix are missing and force is
Truethen after reading fp will be positioned at the start of the file-like.
fp (file-like object) – The file-like to read the preamble from.
force (bool) – Flag to force reading of a file even if no header is found.
preamble – The 128-byte DICOM preamble will be returned if the appropriate prefix (‘DICM’) is found at byte offset 128. Returns
Noneif the ‘DICM’ prefix is not found and force is
- Return type:
bytes or None
InvalidDicomError – If force is
Falseand no appropriate header information found.
Also reads past the ‘DICM’ marker. Rewinds file to the beginning if no header found.