ParallelHttpDownloadWorker class final

Parallel chunked HTTP download worker configuration.

Splits a single file download into numChunks parallel byte-range requests (HTTP/1.1 Range header, RFC 7233), downloads them concurrently on the native side, then merges the parts into a single output file — all without loading the file into memory.

When to use over HttpDownloadWorker:

  • Files larger than ~50 MB where parallel chunks give real speed-up.
  • Servers that support Accept-Ranges: bytes (most CDNs do).
  • When you want faster downloads on high-bandwidth connections.

Automatic fallback: If the server does not advertise Accept-Ranges: bytes or does not return a Content-Length, the worker automatically falls back to a single sequential download (identical to HttpDownloadWorker).

Example

await NativeWorkManager.enqueue(
  taskId: 'big-video',
  trigger: TaskTrigger.oneTime(),
  worker: NativeWorker.parallelHttpDownload(
    url: 'https://cdn.example.com/movie.mp4',
    savePath: '/data/user/0/com.example/files/movie.mp4',
    numChunks: 4,           // default
    showNotification: true,
  ),
  constraints: Constraints.networkRequired,
);

Progress events

Progress is reported as aggregate bytes across all chunks, so the TaskProgress.progress field rises smoothly from 0 to 100 even when chunks finish out of order.

Resume support

Each chunk is saved to savePath.partN temporarily. If the task is interrupted, a subsequent enqueue will pick up any completed parts and only re-download missing or incomplete chunks.

Inheritance
Annotations

Constructors

ParallelHttpDownloadWorker({required String url, required String savePath, int numChunks = 4, Map<String, String> headers = const {}, Duration timeout = const Duration(minutes: 10), String? expectedChecksum, String checksumAlgorithm = 'SHA-256', bool showNotification = false, String? notificationTitle, String? notificationBody, bool skipExisting = false, CertificatePinning? certificatePinning})
const

Properties

certificatePinning → CertificatePinning?
Opt-in TLS certificate pinning for every chunk request. See CertificatePinning.
final
checksumAlgorithm → String
Hashing algorithm for checksum verification (default: 'SHA-256').
final
expectedChecksum → String?
Expected checksum for the merged file (optional).
final
hashCode → int
The hash code for this object.
no setterinherited
headers → Map<String, String>
Optional HTTP headers sent with every chunk request.
final
notificationBody → String?
Body text for the progress notification.
final
notificationTitle → String?
Title for the progress notification.
final
numChunks → int
Number of parallel byte-range chunks (1–16, default 4).
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
savePath → String
Absolute path where the merged file will be saved.
final
showNotification → bool
Show a system notification with aggregate download progress.
final
skipExisting → bool
Skip the download if savePath already exists on disk.
final
timeout → Duration
Per-chunk request timeout (default: 10 minutes).
final
url → String
The URL to download from.
final
workerClassName → String
Get the worker class name for native side.
no setteroverride

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toMap() → Map<String, dynamic>
Convert to map for platform channel.
override
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited