ModelDownloader

class ModelDownloader(transport: HttpTransport = defaultHttpTransport(), fileSystem: ModelFileSystem = defaultModelFileSystem(), chunkSizeBytes: Long = DEFAULT_CHUNK_SIZE, maxRetries: Int = 5, initialRetryDelay: Duration = 500.milliseconds, ioDispatcher: CoroutineDispatcher = modelIoDispatcher(), readBufferSize: Int = 64 * 1024)(source)

Resumable, chunked model downloader using HTTP Range requests.

  • Data is requested in chunkSizeBytes ranges and appended to <destination>.part. An interrupted download (network error, cancellation, app kill) resumes from the partial file's size.

  • Network errors and HTTP 408/429/5xx are retried up to maxRetries times in a row with exponential backoff starting at initialRetryDelay; the counter resets after every chunk that makes progress.

  • Servers that ignore Range (HTTP 200) restart the download from byte 0.

  • The finished file's size and SHA-256 are verified before it is atomically moved to the destination; on a mismatch the partial file is deleted so the next attempt starts clean.

Collection is cancellable at chunk-read granularity; the partial file is kept for a later resume.

Constructors

Link copied to clipboard
constructor(transport: HttpTransport = defaultHttpTransport(), fileSystem: ModelFileSystem = defaultModelFileSystem(), chunkSizeBytes: Long = DEFAULT_CHUNK_SIZE, maxRetries: Int = 5, initialRetryDelay: Duration = 500.milliseconds, ioDispatcher: CoroutineDispatcher = modelIoDispatcher(), readBufferSize: Int = 64 * 1024)

Types

Link copied to clipboard
object Companion

Constants and factory functions of ModelDownloader.

Functions

Link copied to clipboard

Downloads request, emitting DownloadEvents and ending with DownloadEvent.Completed.

Link copied to clipboard

Downloads request and returns the DownloadEvent.Completed event.