Skip to content

Commit c6f581a

Browse files
authored
Merge pull request #37 from generalmimon/fix-bytes-ops
Fix byte array operations
2 parents 4192573 + f8d4ac6 commit c6f581a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

kaitaistruct.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import itertools
22
import sys
33
import struct
4-
from io import BytesIO, SEEK_CUR, SEEK_END # noqa
4+
from io import open, BytesIO, SEEK_CUR, SEEK_END # noqa
55

66
PY2 = sys.version_info[0] == 2
77

@@ -370,6 +370,24 @@ def process_rotate_left(data, amount, group_size):
370370
# Misc
371371
# ========================================================================
372372

373+
@staticmethod
374+
def int_from_byte(v):
375+
if PY2:
376+
return ord(v)
377+
return v
378+
379+
@staticmethod
380+
def byte_array_index(data, i):
381+
return KaitaiStream.int_from_byte(data[i])
382+
383+
@staticmethod
384+
def byte_array_min(b):
385+
return KaitaiStream.int_from_byte(min(b))
386+
387+
@staticmethod
388+
def byte_array_max(b):
389+
return KaitaiStream.int_from_byte(max(b))
390+
373391
@staticmethod
374392
def resolve_enum(enum_obj, value):
375393
"""Resolves value using enum: if the value is not found in the map,

0 commit comments

Comments
 (0)