QVAC Logo
How-to guides

Download lifecycle

Pause and resume model downloads.

Overview

Downloads in QVAC are resumable by default. When you download an asset via downloadAsset() or loadModel()), the SDK writes partial files to disk so the next run can continue from where it left off. The progress callback provides a downloadKey. Persist it if you want to programmatically pause/cancel the download.

Functions

  1. downloadAsset() or loadModel() — with onProgress for progress tracking
  2. cancel() — pause/cancel a download using the downloadKey

For how to use each function, see SDK — API reference.

Flow

  • Pause: call cancel() with operation: "downloadAsset" and the downloadKey from progress events.
  • Resume: run the same downloadAsset() / loadModel() call again — the SDK will reuse the partial file and continue downloading.
  • Discard partial file: call cancel({ ..., clearCache: true }).

Example

The following script shows an example of pausing and resuming a download using cancel() + downloadKey:

download-lifecycle.js
import { cancel, close, downloadAsset, LLAMA_3_2_1B_INST_Q4_0, } from "@qvac/sdk";
console.log(`🚀 Starting download with pause/resume example`);
console.log(`\n💡 Press Ctrl+C to pause the download (it will resume on restart)\n`);
let modelId;
let cancelled = false;
try {
    // Download model with progress tracking and cancellation
    await downloadAsset({
        assetSrc: LLAMA_3_2_1B_INST_Q4_0,
        onProgress: (progress) => {
            const downloadedMB = (progress.downloaded / 1024 / 1024).toFixed(2);
            const totalMB = (progress.total / 1024 / 1024).toFixed(2);
            const percentage = progress.percentage.toFixed(1);
            console.log(`📊 Progress: ${percentage}% (${downloadedMB}MB / ${totalMB}MB)`);
            // Example: Stops at 10% (or use Ctrl+C for manual stop)
            if (parseFloat(percentage) >= 10 && !cancelled) {
                console.log("\n🚫 Auto-cancelling at 10% for demo purposes...,");
                console.log(`📊 Progress: ${percentage}% (${downloadedMB}MB / ${totalMB}MB)`);
                console.log(progress);
                cancelled = true;
                // Use the downloadKey to cancel
                if (progress.downloadKey) {
                    void cancel({
                        operation: "downloadAsset",
                        downloadKey: progress.downloadKey,
                        // clearCache: true, // Uncomment to delete partial file instead of resuming
                    });
                }
            }
        },
    });
    console.log(`\n✅ Model downloaded successfully! Model ID: ${modelId}`);
    console.log("🎯 Download completed without interruption");
    void close();
}
catch (error) {
    if (error instanceof Error && error.message.includes("cancelled")) {
        console.log("✅ Download was successfully cancelled");
        void close();
    }
    else {
        console.error("❌ Error:", error);
        process.exit(1);
    }
}

Tip: all examples throughout this documentation are self-contained and runnable. For instructions on how to run them, see SDK quickstart.

On this page