pydicom.filebase.DicomBytesIO¶
- class pydicom.filebase.DicomBytesIO(initial_bytes: bytes | bytearray | memoryview = b'')[source]¶
Wrapper for
io.BytesIO
to simplify encoding/decoding DICOM datasets.See also
- __init__(initial_bytes: bytes | bytearray | memoryview = b'') None [source]¶
Create a new DicomBytesIO instance.
- Parameters:
buffer (bytes | bytearray | memoryview, optional) – The buffer to write to or read from, default is an empty buffer.
Methods
__init__
([initial_bytes])Create a new DicomBytesIO 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.