diff --git a/CHANGELOG.md b/CHANGELOG.md index 43a0bee..ae5d96d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ This file logs the changes that are actually interesting to users (new features, changed functionality, fixed bugs). +# Version 1.16 (in development) + +- Add `BlendFileBlock.raw_data()` and `.as_string()` functions. These functions interpret the data in a `BlendFileBlock` as either `bytes` or `string`. This can be used to obtain the contents of a `char*` (instead of the more common embedded `char[N]` array). + # Version 1.15 (2022-12-16) - Add support for fluid simulation caches. diff --git a/blender_asset_tracer/blendfile/__init__.py b/blender_asset_tracer/blendfile/__init__.py index 4b6cd10..9516b78 100644 --- a/blender_asset_tracer/blendfile/__init__.py +++ b/blender_asset_tracer/blendfile/__init__.py @@ -610,6 +610,23 @@ class BlendFileBlock: return value, field return value + def raw_data(self) -> bytes: + """Read low-level raw data of this datablock.""" + self.bfile.fileobj.seek(self.file_offset, os.SEEK_SET) + return self.bfile.fileobj.read(self.size) + + def as_string(self) -> str: + """Interpret the bytes of this datablock as null-terminated utf8 string.""" + the_bytes = self.raw_data() + try: + first_null = the_bytes.index(0) + except ValueError: + pass + else: + the_bytes = the_bytes[:first_null] + return the_bytes.decode() + + def get_recursive_iter( self, path: dna.FieldPath,