def bytearray(source: Union[bytes, Iterable[int]] = b'', /) -> ByteArrayObject
Creates a persistent, mutable sequence of bytes that behaves like Python's built-in bytearray.
Familiar API: This class is designed as a persistent counterpart to Python's built-in collection. It implements the same interface and supports all standard operations, allowing you to use it easily as a drop-in replacement while providing automatic persistance.
Parameters
sourcebytes or Iterable[int], default b''
Optional bytes-like object or iterable of integers (0-255) to initialize the byte array. Defaults to empty if not provided.
Returns
A new dbzero.bytearray object.
Examples
Creating and modifying a bytearray
You can create and manipulate a dbzero.bytearray just like a standard one.
# Create a new db0.bytearray
raw_data = db0.bytearray(b'log_level:info')
# Modify it in-place
raw_data.extend(b', user:admin')
raw_data[11:15] = b'warn'
# The final data is b'log_level:warn, user:admin'
print(raw_data.decode())
# Expected output: log_level:warn, user:admin