API reference

PakDownloader Interface

Interface for the network transport layer. The 3p implements this with their preferred HTTP client (OkHttp, Volley, custom CDN client, etc.).
Unlike AssetFetcher, this interface supports progress reporting, resume from a byte offset, and cancellation.
Implementations MUST:

Signature

interface PakDownloader

Methods

download ( uri , outFile , resumeFromByte , sink )
Starts downloading uri into outFile, optionally resuming from resumeFromByte.
The implementation writes directly to outFile (append mode if resuming). Progress and completion are reported via sink.
This method is called on a background thread. It may block or use async I/O internally — the contract is that sink callbacks are the completion signal.
Signature
abstract fun download(uri: Uri, outFile: File, resumeFromByte: Long, sink: PakDownloader.ProgressSink)
Parameters
uri: Uri
outFile: File
resumeFromByte: Long
sink: PakDownloader.ProgressSink
download ( uri , outFile , resumeFromByte , sink , headers )
Starts downloading uri into outFile with additional HTTP headers.
Override this to support authorization headers, API keys, or CDN-specific headers. The default implementation delegates to the 4-param PakDownloader.download, ignoring headers — override if your transport needs them.
Signature
open fun download(uri: Uri, outFile: File, resumeFromByte: Long, sink: PakDownloader.ProgressSink, headers: Map<String, String>)
Parameters
uri: Uri
outFile: File
resumeFromByte: Long
sink: PakDownloader.ProgressSink
headers: Map  Additional HTTP headers (e.g. "Authorization" to "Bearer <token>").
download ( uri , outFile , resumeFromByte , sink , headers , refreshAuthHeaders )
Starts downloading uri into outFile with HTTP headers and an optional auth-failure refresh callback.
Override this if your transport supports auth refresh (e.g. on 401/403 the downloader calls refreshAuthHeaders with the status code, and if it returns non-null, retries the request once with the new headers). The default implementation delegates to the 5-param overload, ignoring refreshAuthHeaders.
Signature
open fun download(uri: Uri, outFile: File, resumeFromByte: Long, sink: PakDownloader.ProgressSink, headers: Map<String, String>, refreshAuthHeaders: (Int) -> Map<String, String>??)
Parameters
uri: Uri
outFile: File
resumeFromByte: Long
sink: PakDownloader.ProgressSink
headers: Map
refreshAuthHeaders: Function1?

Inner Interface

ProgressSink Interface

Callback sink provided to PakDownloader.download. Thread-safe — may be called from any thread.

Signature

interface ProgressSink

Properties

isCancelled : Boolean
[Get]
Returns true if the download has been cancelled by the caller.
Signature
abstract val isCancelled: Boolean

Methods

onComplete ()
Download completed successfully. The file is fully written.
Signature
abstract fun onComplete()
onError ( exception )
Download failed.
Signature
abstract fun onError(exception: Exception)
Parameters
exception: Exception
onProgress ( bytesDownloaded , totalBytes )
Report bytes written so far (cumulative, including resumed bytes).
Signature
abstract fun onProgress(bytesDownloaded: Long, totalBytes: Long?)
Parameters
bytesDownloaded: Long
totalBytes: Long?