def is_text_by_content_analysis(content: bytes) -> bool:
    """Analyze if content is likely text based on encoding detection and character distribution.

    Args:
        content: Binary content to analyze

    Returns:
        True if the content is likely text, False otherwise
    """
    if not content:
        return False

    # Try to detect encoding, if it succeeds with high confidence, it's likely text
    detection = chardet.detect(content[:ENCODING_SAMPLE_SIZE])
    if (
        detection
        and detection["confidence"] > MIN_ENCODING_CONFIDENCE
        and detection["encoding"] is not None
    ):
        try:
            # Try to decode the content, if it succeeds it's likely text
            content[:ENCODING_SAMPLE_SIZE].decode(detection["encoding"], errors="strict")
            return True
        except UnicodeDecodeError:
            return False

    # Check for common binary sequences
    if b"\x00" in content[:ENCODING_SAMPLE_SIZE]:
        return False

    # Text files typically have a high ratio of printable ASCII characters
    sample = content[:ASCII_SAMPLE_SIZE] if len(content) > ASCII_SAMPLE_SIZE else content
    if not sample:
        return False

    ascii_count = sum(
        1 for b in sample if 32 <= b <= 126 or b in (9, 10, 13)
    )  # printable + whitespace
    ascii_ratio = ascii_count / len(sample)

    return ascii_ratio > MIN_ASCII_RATIO
Analyze if content is likely text based on encoding detection and character distribution.

    Args:
        content: Binary content to analyze

    Returns:
        True if the content is likely text, False otherwise
    
backend/airweave/platform/utils/file_extensions.py