def is_binary(location): """ Retrun True if the file at `location` is a binary file. """ known_extensions = ('.pyc', '.pgm', '.mp3', '.mp4', '.mpeg', '.mpg', '.emf', '.pgm', '.pbm', '.ppm') if location.endswith(known_extensions): return True return is_binary_string(get_starting_chunk(location))
def is_binary(filename): """ :param filename: File to check. :returns: True if it's a binary file, otherwise False. """ logger.debug('is_binary: %(filename)r', locals()) # Check if the file extension is in a list of known binary types # binary_extensions = ['.pyc', ] # for ext in binary_extensions: # if filename.endswith(ext): # return True # Check if the starting chunk is a binary string chunk = get_starting_chunk(filename) return is_binary_string(chunk)