def readNum(fobj):
    """
    Reads a ULEB encoded number from a stream.
    """
    n = 0
    shift = 0
    while True:
        b = bytearray(fobj.read(1))[0]
        n |= (b & 0x7F) << shift
        shift += 7
        if (b & 0x80) == 0:
            return n