@@ -326,7 +326,7 @@ class NiftiExtension(ty.Generic[T]):
326
326
327
327
code : int
328
328
encoding : str | None = None
329
- _content : bytes
329
+ _raw : bytes
330
330
_object : T | None = None
331
331
332
332
def __init__ (
@@ -351,10 +351,14 @@ def __init__(
351
351
self .code = extension_codes .code [code ] # type: ignore[assignment]
352
352
except KeyError :
353
353
self .code = code # type: ignore[assignment]
354
- self ._content = content
354
+ self ._raw = content
355
355
if object is not None :
356
356
self ._object = object
357
357
358
+ @property
359
+ def _content (self ):
360
+ return self .get_object ()
361
+
358
362
@classmethod
359
363
def from_bytes (cls , content : bytes ) -> Self :
360
364
"""Create an extension from raw bytes.
@@ -394,15 +398,15 @@ def _sync(self) -> None:
394
398
and updates the bytes representation accordingly.
395
399
"""
396
400
if self ._object is not None :
397
- self ._content = self ._mangle (self ._object )
401
+ self ._raw = self ._mangle (self ._object )
398
402
399
403
def __repr__ (self ) -> str :
400
404
try :
401
405
code = extension_codes .label [self .code ]
402
406
except KeyError :
403
407
# deal with unknown codes
404
408
code = self .code
405
- return f'{ self .__class__ .__name__ } ({ code } , { self ._content !r} )'
409
+ return f'{ self .__class__ .__name__ } ({ code } , { self ._raw !r} )'
406
410
407
411
def __eq__ (self , other : object ) -> bool :
408
412
return (
@@ -425,7 +429,7 @@ def get_code(self):
425
429
def content (self ) -> bytes :
426
430
"""Return the extension content as raw bytes."""
427
431
self ._sync ()
428
- return self ._content
432
+ return self ._raw
429
433
430
434
@property
431
435
def text (self ) -> str :
@@ -452,7 +456,7 @@ def get_object(self) -> T:
452
456
instead.
453
457
"""
454
458
if self ._object is None :
455
- self ._object = self ._unmangle (self ._content )
459
+ self ._object = self ._unmangle (self ._raw )
456
460
return self ._object
457
461
458
462
# Backwards compatibility
@@ -488,7 +492,7 @@ def write_to(self, fileobj: ty.BinaryIO, byteswap: bool = False) -> None:
488
492
extinfo = extinfo .byteswap ()
489
493
fileobj .write (extinfo .tobytes ())
490
494
# followed by the actual extension content, synced above
491
- fileobj .write (self ._content )
495
+ fileobj .write (self ._raw )
492
496
# be nice and zero out remaining part of the extension till the
493
497
# next 16 byte border
494
498
pad = extstart + rawsize - fileobj .tell ()
0 commit comments