Files
fn_registry/functions/infra/http_download_file.md
T
egutierrez 9c0d24d3ef feat: funciones Go — core (cron, join_by_key, validate_struct), datascience (pivot, diff_entities), infra (http, cache, cron_ticker)
Nuevas funciones Go con tests en tres dominios:
- core: parse_cron_expr, next_cron_time, join_by_key, validate_struct_fields + tipo CronSchedule
- datascience: pivot (tabla dinámica), diff_entities (comparación de entidades)
- infra: http_get_json, http_post_json, http_download_file, cache_to_sqlite, cron_ticker

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 17:11:12 +02:00

1.5 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, 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 tested tests test_file_path file_path
http_download_file function go infra 1.0.0 impure func HttpDownloadFile(url, destPath string, headers map[string]string, timeout time.Duration) (int64, error) Descarga url en destPath en streaming con io.Copy. Crea directorios con os.MkdirAll. Usa archivo temporal + rename para atomicidad (no deja archivo corrupto si falla). Retorna bytes escritos.
http
download
file
streaming
atomic
network
stdlib
infra
false error_go_core
fmt
io
net/http
os
path/filepath
time
true
httptest.Server sirve archivo binario
Directorio creado automaticamente
Archivo temporal + rename (no deja basura si falla)
Size retornado coincide
functions/infra/http_download_file_test.go functions/infra/http_download_file.go

Ejemplo

n, err := HttpDownloadFile(
    "https://example.com/report.pdf",
    "/tmp/reports/report.pdf",
    nil,
    2*time.Minute,
)
if err != nil {
    return err
}
fmt.Printf("Downloaded %d bytes\n", n)

Notas

Solo usa stdlib. El archivo temporal se crea en el mismo directorio que destPath para que el rename sea atomico (mismo filesystem). Si la descarga falla, el archivo temporal se elimina con os.Remove (el defer lo garantiza). Compatible con archivos de cualquier tamano ya que usa streaming con io.Copy.