From b301cffd61be0fdec9fec2e65995778e41c2fb33 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Fri, 11 Mar 2022 15:25:20 -0500 Subject: Allow DataBuffer to be initialized with a bytearray. --- python/databuffer.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/python/databuffer.py b/python/databuffer.py index f4905cbd..bbcdd37b 100644 --- a/python/databuffer.py +++ b/python/databuffer.py @@ -37,10 +37,14 @@ class DataBuffer: self.handle = core.BNDuplicateDataBuffer(contents.handle) elif isinstance(contents, str): self.handle = core.BNCreateDataBuffer(contents.encode("utf-8"), len(contents.encode("utf-8"))) - else: - if not isinstance(contents, bytes): - raise TypeError(f"type {type(contents)} not convertable to DataBuffer") + elif isinstance(contents, bytes): self.handle = core.BNCreateDataBuffer(contents, len(contents)) + elif isinstance(contents, bytearray): + b = bytes(contents) + self.handle = core.BNCreateDataBuffer(b, len(b)) + else: + raise TypeError(f"type {type(contents)} not convertable to DataBuffer") + def __del__(self): if core is not None: -- cgit v1.3.1