Merging byte arrays

G

Gabriel

Hello
I'm using this function to read data in byte format from file

def readBytes(file, offset, size):
file.seek(offset)
return file.read(size)

file is opened with open function:

file = open(path, "rb")

then i'm using array.array('B', bytes) to parse read-out data, for
example in this function:

def getIntValOfBytes(bytes):
value = i = 0
for byte in array.array('B', bytes):
value |= byte << (8 * i)
i += 1

return value

when i read one portion of bytes everything works ok. but now i need
read from more locations in file, then somehow merge these data together
and then pass to getIntValOfBytes function..

i tried list

list = []
for offset in offsets
list.extend(readBytes(file, offset, size))

or string

string = ""
for offset in offsets
string += readBytes(file, offset, size)

but with list i get this error

for byte in array.array('B', bytes):
TypeError: an integer is required

in getIntValOfBytes (i passed the part of the list to the method, list[x:y])

and with string it just freeze....

I will appreciate any help..
[I'm newbie so sorry if i'm missing something obvious]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top