Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions construct/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ def _parse(self, stream, context, path):
def _build(self, obj, stream, context, path):
length = self.length(context) if callable(self.length) else self.length
data = integer2bytes(obj, length) if isinstance(obj, int) else obj
data = bytes(data) if type(data) is bytearray else data
data = bytes(data) if isinstance(data, bytearray) else data
stream_write(stream, data, length, path)
return data

Expand Down Expand Up @@ -1013,7 +1013,7 @@ def _parse(self, stream, context, path):
return stream_read_entire(stream, path)

def _build(self, obj, stream, context, path):
data = bytes(obj) if type(obj) is bytearray else obj
data = bytes(obj) if isinstance(obj, bytearray) else obj
stream_write(stream, data, len(data), path)
return data

Expand Down Expand Up @@ -2835,7 +2835,7 @@ class Const(Subconstruct):

def __init__(self, value, subcon=None):
if subcon is None:
if not isinstance(value, bytes):
if not isinstance(value, bytes) and not isinstance(value, bytearray):
raise StringError(f"given non-bytes value {repr(value)}, perhaps unicode?")
subcon = Bytes(len(value))
super().__init__(subcon)
Expand Down