import struct


def bytoi(blob):
    """Converts a string of bytes or a bytearray to unsigned integer."""
    fmt = {1: "<B", 2: "<H", 4: "<L", 8: "<Q"}[len(blob)]
    return struct.unpack(fmt, blob)[0]