import struct


def unpack(fmt, data):
    """Unpack bytes according to format string."""
    output = struct.unpack(fmt, data.read(struct.calcsize(fmt)))
    if len(output) == 1:
        return output[0]
    return output