---
title: "Downloader y tipos"
description: "Referencia de la clase NodeDownloader y de las interfaces TypeScript exportadas por el paquete."
canonical_url: "https://nodecfdi.com/packages/xml-resource-retriever/api-reference/downloader-and-types"
---

> Index of every page on this site: [llms.txt](https://nodecfdi.com/llms.txt)

`NodeDownloader` se importa desde el punto de entrada principal, mientras que las interfaces y tipos se importan desde `@nodecfdi/xml-resource-retriever/types`.

```ts
import type {
  DownloaderInterface,
  NodeDownloaderOptions,
  RetrieverInterface,
  SearchElement,
  UrlParts,
} from '@nodecfdi/xml-resource-retriever/types';
import { NodeDownloader } from '@nodecfdi/xml-resource-retriever';
```

## `NodeDownloader`

Implementa `DownloaderInterface` usando `fetch` nativo de Node.js con escritura atómica.

### Constructor

```ts
declare class NodeDownloader implements DownloaderInterface {
  public constructor(options?: NodeDownloaderOptions);
}
```

- Valida `timeoutMs` (defecto `30_000`) y `maxBytes` (defecto `52_428_800`) con `validateNonNegativeFinite`. Lanza `RangeError` si son negativos, `NaN` o `Infinity`.
- Reenvía cualquier otra propiedad de `RequestInit` a `fetch`.

### `downloadTo(source: string, destination: string): Promise<void>`

Descarga `source` hacia un archivo temporal `${destination}.${uuid}.tmp` y lo renombra a `destination` al completarse.

- Lanza `AggregateError` con el mensaje ``Unable to download ${source} to ${destination}`` y la causa original en `error.errors[0]` ante cualquier error de protocolo, red, HTTP no exitoso, límite de bytes, timeout o escritura en disco.

---

## Interfaces y tipos

### `RetrieverInterface`

```ts
export interface RetrieverInterface {
  getBasePath: () => string;
  buildPath: (url: string) => string;
  retrieve: (url: string) => Promise<string>;
  retrieveHistory: () => Record<string, string>;
  download: (url: string) => Promise<string>;
}
```

### `DownloaderInterface`

```ts
export interface DownloaderInterface {
  downloadTo: (source: string, destination: string) => Promise<void>;
}
```

### `NodeDownloaderOptions`

```ts
export interface NodeDownloaderOptions extends RequestInit {
  /**
   * Tiempo máximo en milisegundos para la petición y descarga del cuerpo.
   * Usa `0` para desactivar el timeout.
   * @defaultValue 30_000
   */
  timeoutMs?: number;

  /**
   * Tamaño máximo permitido de la respuesta en bytes.
   * Usa `0` para desactivar el límite.
   * @defaultValue 52_428_800 (50 MiB)
   */
  maxBytes?: number;
}
```

### `SearchElement`

```ts
export interface SearchElement {
  element: string;
  attribute: string;
}
```

### `UrlParts`

```ts
export interface UrlParts {
  scheme: string;
  host: string;
  port: string;
  path: string;
}
```

## Sitemap

See the full [sitemap](https://nodecfdi.com/sitemap.md) for all pages.
