Docs/API reference

Downloader · Node.js

Save a response to a local file or receive its bytes in memory.

Download .md
Developers3 min read10 sections
Source reference · Match your SDK version. Availability and known issues
In this guide

Purpose and lifecycle

allowResume uses HTTP Range when resuming an existing file. Inspect resumed and status rather than assuming the server honored the range.

The underlying transport buffers the response and applies its response-size cap. This is not an unlimited streaming downloader; chunk_size controls file writes, not network memory.

maxBytes/max_bytes limits the bytes retained/written after fetching. It does not make the upstream transfer stop at that exact byte count.

Definition and availability

Source snapshot: 1.0.0-alpha.3. Package export. Declared in source; this is not a runtime test result.

Signatures and source locations are generated from the SDK wrappers. Clean snapshots link to the recorded commit. Modified snapshots link to main, which may differ; file hashes identify the local inputs.

export class Downloader
typescript1 lines · copy-ready

Usage example

Use a matching source build. Where a snippet uses page, obtain it with the Page example first. Example URLs illustrate API shape; they are not promised datasets.

import { Downloader, Session } from 'crawlingo';
const result = await new Downloader(new Session().retries(2))
  .allowResume(true).maxBytes(1048576)
  .download('https://example.com/', 'page.html');
console.log(result.status, result.bytesWritten, result.resumed);
typescript5 lines · copy-ready

Members

MemberKindReturn / value typeSource status
constructormethodDownloaderPresent in source
allowResumemethodthisPresent in source
maxBytesmethodthisPresent in source
downloadmethodPromise<DownloadResult>Present in source
downloadToMemorymethodPromise<{ result: DownloadResult; data: Buffer; }>Present in source

constructor()

Create a downloader using a supplied session or a fresh default session. Configure limits and call download or download_to_memory.

Returns / value: Downloader.

constructor(session?: Session): Downloader
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
sessionSession | undefinedOptionalShared request state. Omit only where the signature provides a default.

allowResume()

Enable or disable range-based continuation of an existing destination file.

Returns / value: this.

allowResume(enabled: boolean): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
enabledbooleanRequiredEnable or disable this behavior.

maxBytes()

Limit the returned/written body bytes. Choose a positive integer.

Returns / value: this.

maxBytes(n: number): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
nnumberRequiredCount or index; see the method description.

download()

Fetch into the destination and return DownloadResult. This can append or replace depending on resume/server response.

Returns / value: Promise<DownloadResult>.

download(url: string, dest: string): Promise<DownloadResult>
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
urlstringRequiredHTTP(S) source URL; verify the target is appropriate for your application.
deststringRequiredDestination file path; existing content may be replaced or resumed.

downloadToMemory()

Return result metadata and the response bytes; retain only small downloads this way.

Returns / value: Promise<{ result: DownloadResult; data: Buffer; }>.

downloadToMemory(url: string): Promise<{ result: DownloadResult; data: Buffer; }>
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
urlstringRequiredHTTP(S) source URL; verify the target is appropriate for your application.

Errors and operational limits

Network, timeout and filesystem failures can propagate. Node uses typed native errors; Python downloader methods may propagate native exceptions directly.

Source availability, package publication and runtime validation are separate facts. These pages describe the source snapshot, not a claim that all platforms or every API path have passed production acceptance.