def strUnpad(text_as_bytes, pad=0):
    """Convert a bytes or bytearray
       to a str removing trailing bytes matching int pad."""
    text_b = bytes(text_as_bytes)  # bytes type has the useful methods
    if pad is not None:
        text_b = text_b.rstrip(bytes([pad]))

    return text_b.decode("utf-8")