diff --git a/nd2reader/reader.py b/nd2reader/reader.py index 20ab5d2..fecf17f 100644 --- a/nd2reader/reader.py +++ b/nd2reader/reader.py @@ -228,48 +228,49 @@ class Nd2FileReader(object): def read_lv_encoding(self, data, count): data = StringIO(data) - res = {} + metadata = {} total_count = 0 - for c in range(count): - lastpos = data.tell() + for _ in xrange(count): + cursor_position = data.tell() total_count += 1 - hdr = data.read(2) - if not hdr: + header = data.read(2) + if not header: break - typ = ord(hdr[0]) - bname = data.read(2*ord(hdr[1])) - name = bname.decode("utf16")[:-1].encode("utf8") - if typ == 1: + data_type, name_length = map(ord, header) + name = data.read(name_length * 2).decode("utf16")[:-1].encode("utf8") + if data_type == 1: value, = struct.unpack("B", data.read(1)) - elif typ in [2, 3]: + elif data_type in [2, 3]: value, = struct.unpack("I", data.read(4)) - elif typ == 5: + elif data_type == 5: value, = struct.unpack("Q", data.read(8)) - elif typ == 6: + elif data_type == 6: value, = struct.unpack("d", data.read(8)) - elif typ == 8: + elif data_type == 8: value = data.read(2) while value[-2:] != "\x00\x00": value += data.read(2) value = value.decode("utf16")[:-1].encode("utf8") - elif typ == 9: + elif data_type == 9: cnt, = struct.unpack("Q", data.read(8)) value = array.array("B", data.read(cnt)) - elif typ == 11: - newcount, length = struct.unpack("