def is_text(s, threshold=0.3):
    """
    Determine whether a certain string is text or arbitrary bytes.
    This is derived from Python Cookbook
    :param s: string, input string
    :param threshold: float, threshold for the max proportion in a string which can be null translates
    :return: 
    """
    # import string
    text_characters = "".join(map(chr, range(32, 127)))+"\n\r\t\b"
    _null_trans = str.maketrans("", "")
    if "\0" in s:
        return False
    if not s:
        return True
    t = text_characters.translate(_null_trans)
    return len(t)/len(s) <= threshold