47fac22230
- .claude/CLAUDE.md - .claude/commands/subagentes.md - .claude/rules/INDEX.md - .mcp.json - bash/functions/cybersecurity/analyze_dns.md - bash/functions/cybersecurity/audit_http_headers.md - bash/functions/cybersecurity/audit_ssh_config.md - bash/functions/cybersecurity/check_firewall.md - bash/functions/cybersecurity/detect_suspicious_users.md - bash/functions/cybersecurity/encrypt_file.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2.1 KiB
2.1 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| read_file_with_encoding | function | py | infra | 1.0.0 | impure | read_file_with_encoding(path: str, encodings: list[str] | None = None) -> str | Lee un archivo de texto intentando multiples encodings en orden hasta encontrar uno que funcione. Util para archivos de origen desconocido (Windows, Latin-1, con BOM, etc.). |
|
false | error_go_core |
|
string con el contenido del archivo decodificado | true |
|
python/functions/infra/read_file_with_encoding_test.py | python/functions/infra/read_file_with_encoding.py |
Ejemplo
# Leer archivo de origen desconocido
content = read_file_with_encoding("/tmp/datos.csv")
# Leer archivo Windows con BOM explicitamente
content = read_file_with_encoding("/tmp/report.txt", encodings=["utf-8-sig", "cp1252"])
Notas
Los encodings por defecto son ["utf-8", "utf-8-sig", "latin-1", "cp1252"]. El orden importa: utf-8 se intenta primero porque es el mas comun. Si el archivo tiene BOM y se quiere que sea eliminado automaticamente, pasar encodings=["utf-8-sig"] o anteponerlo a utf-8 en la lista personalizada.
latin-1 nunca lanza UnicodeDecodeError porque mapea todos los bytes 0x00-0xFF, por lo que actua como fallback universal. Si latin-1 es el ultimo encoding y falla con cp1252 tambien, solo un archivo binario puro (sin mapeo posible) disparara el ValueError.
Raises FileNotFoundError u OSError nativas si el archivo no existe o hay error de I/O — estos no se envuelven en ValueError.