def readUVARI(stream):
    """
    Reads a Variable-Length Unsigned Integer from stream

    :type stream: FileIO or BytesIO
    :param stream: Where to read from

    :return: result
    :rtype: int

    """
    b = stream.read(1)[0]
    if b & 0x80:
        if b & 0x40:
            b &= 0x3F
            for i in range(3):
                b <<= 8
                b |= stream.read(1)[0]
        else:
            b &= 0x7F
            b <<= 8
            b |= stream.read(1)[0]
    return b