diff --git a/pymule/compress.py b/pymule/compress.py index 6691199458d3cbf0ac1c8d3c4888449179cf03ab..b6789c5c46a487afd5e4bf3e937b0f7074251ceb 100644 --- a/pymule/compress.py +++ b/pymule/compress.py @@ -1,6 +1,7 @@ # https://mathematica.stackexchange.com/a/104696 import zlib import base64 +import struct import StringIO @@ -11,3 +12,26 @@ def decomp(b): if fp.read(4) != "!boR": raise KeyError("Header is not matching") return fp + + +def parse(fp): + ans = [] + cur = [] + while True: + cmd = fp.read(1) + if cmd == '': + ans.append(cur) + return ans + elif cmd == 'i': + cur.append(struct.unpack('<i', fp.read(4))[0]) + elif cmd == 'S' or cmd == 's': + le = struct.unpack('<i', fp.read(4))[0] + cur.append(fp.read(le)) + elif cmd == 'r': + cur.append(struct.unpack('<d', fp.read(8))[0]) + elif cmd == 'f': + le = struct.unpack('<i', fp.read(4))[0] + ans.append(cur[:]) + cur = [] + else: + raise KeyError("Unknown cmd %s" % cmd)