pydicom.filebase.DicomFileLike¶
- class pydicom.filebase.DicomFileLike(buffer: ReadableBuffer | WriteableBuffer)[source]¶
Wrapper for file-likes to simplify encoding/decoding DICOM datasets.
See also
- __init__(buffer: ReadableBuffer | WriteableBuffer) None [source]¶
Create a new
DicomIO
instance.- Parameters:
buffer (buffer-like object) –
A buffer-like object that implements:
seek()
andtell()
methods with the same signatures asio.IOBase.seek()
andio.IOBase.tell()
a
read()
method with the same signature asio.RawIOBase.read()
if it supports reading data from itself, and/ora
write()
method with the same signature asio.RawIOBase.write()
if it supports writing data to itself
If buffer supports reading it can be used with
dcmread()
as the source to decode a DICOM dataset from, and if it supports writing it can be used withdcmwrite()
as the destination for the encoded DICOM dataset.
Methods
__init__
(buffer)Create a new
DicomIO
instance.close
(*args, **kwargs)Close the buffer (if possible)
read
([size])Read up to size bytes from the buffer and return them.
read_UL
()Return a UL value read from the buffer.
read_US
()Return a US value read from the buffer.
read_exact
(length[, nr_retries])Return length bytes read from the buffer.
read_tag
()Return a DICOM tag value read from the buffer.
seek
(offset[, whence])Change the buffer position to the given byte offset, relative to the position indicated by whence and return the new absolute position.
tell
()Return the current stream position of the buffer
write
(b, /)Write the bytes-like object b to the buffer and return the number of bytes written.
write_UL
(val)Write a UL value to the buffer.
write_US
(val)Write a US value to the buffer.
write_tag
(tag)Write a DICOM tag to the buffer.
Attributes
Get/set the VR mode for encoding/decoding.
Get/set the endianness for encoding/decoding,
True
for little endian andFalse
for big endian.Return the value of the
parent
'sname
attribute, orNone
if no such attribute.Return the buffer object being wrapped.
- property is_implicit_VR: bool¶
Get/set the VR mode for encoding/decoding.
True
for implicit VR andFalse
for explicit VR.
- property is_little_endian: bool¶
Get/set the endianness for encoding/decoding,
True
for little endian andFalse
for big endian.
- property name: str | None¶
Return the value of the
parent
’sname
attribute, orNone
if no such attribute.
- property parent: ReadableBuffer | WriteableBuffer¶
Return the buffer object being wrapped.
- read(size: int = -1, /) bytes [source]¶
Read up to size bytes from the buffer and return them. If size is unspecified, all bytes until EOF are returned.
Fewer than size bytes may be returned if the operating system call returns fewer than size bytes.
- read_exact(length: int, nr_retries: int = 3) bytes [source]¶
Return length bytes read from the buffer.
- Parameters:
- Returns:
The read data.
- Return type:
- Raises:
EOFError – If unable to read length bytes.
- seek(offset: int, whence: int = 0, /) int [source]¶
Change the buffer position to the given byte offset, relative to the position indicated by whence and return the new absolute position.