Skip to content

Web Downloader API Reference

This page documents the full API surface of the MASV Web Downloader SDK (@masvio/downloader). For a guided walkthrough, see the Getting Started guide.

import { Downloader } from "@masvio/downloader";
const downloader = new Downloader(masvLink, linkPassword, userToken, apiBaseURL, chunkSize);
ParameterTypeRequiredDescription
masvLinkstringYesThe download link of the Package being downloaded. Obtained from the Package download page. After instantiation, the downloader can download contents from this Package only. A new downloader must be instantiated for each download attempt (not including pause and resume).
linkPasswordstringConditionalThe password for the MASV download link. Required only if a password has been set for the link.
userTokenstringConditionalA MASV user token used for download links that require user authentication. Required only if user authentication is enabled for the link.
apiBaseURLstringNoThe base URL of the MASV API. Default: https://api.massive.app.
chunkSizenumberNoThe size of each download chunk in bytes. Default: 104857600 (100 MiB).

Required for bootstrapping the Downloader instance. Must be called before start(). Implicitly calls loadFiles() to retrieve the file list from the download link.

await downloader.initialize();

Starts the download or resumes a paused download.

await downloader.start(directoryHandle, fileList);
ParameterTypeRequiredDescription
directoryHandleFileSystemDirectoryHandleYesThe directory where the Package contents will be downloaded to. Obtained via showDirectoryPicker().
fileListBaseFile[]NoAn array of files to download. If omitted, all files from the download link are downloaded.

Pauses the download. In-flight chunk requests are aborted. Call start() to resume.

downloader.pause();

Resumes the download and retries any failed files. Only valid when the downloader is in the PartialFinished state.

await downloader.retry();

Cancels the download. The downloader cannot perform any further downloads after cancellation.

downloader.cancel();

Terminates the downloader and all of its workers. The downloader cannot perform any other actions after termination. Use this to clean up resources when the downloader is no longer needed.

downloader.terminate();

Retrieves all files from the download link the Downloader is instantiated with. Returns an array of BaseFile objects.

const files = await downloader.loadFiles();

Represents a file available for download from the Package.

PropertyTypeDescription
idstringUnique identifier for the file.
kindstringThe file type. Possible values: file, directory, metadata, zip_windows, zip_mac.
last_modifiedstringThe last modified timestamp of the file.
namestringThe file name.
pathstringThe relative file path, used to preserve folder structures. May be undefined.
sizenumberThe size of the file in bytes. May be undefined.
virus_detectedbooleanIndicates whether a virus has been detected. Files with this field set to true are not downloaded and the downloader emits a FileErrored event instead.
completedbooleanIndicates that the file is ready for download. Only relevant for MASV-generated zip files.

Every event callback receives an object with the following structure:

PropertyTypeDescription
eventstringThe event name (one of the values listed in the events table).
dataobjectEvent-specific data relevant to the event type.
timenumberA Unix timestamp indicating when the event was fired.
targetobjectThe downloader module that fired the event.

Performance statistics returned in Progress, Finished, PartialFinished, Error, and Retry event payloads.

PropertyTypeDescription
durationnumberMilliseconds elapsed since the download started.
speednumberAverage download speed calculated from total progress and duration. Measured in bits per second.
instantnumberMost recent download speed measurement. Measured in bits per second.
movingnumberDownload speed over a recent period (short-term average). Measured in bits per second.
totalnumberSize of the entire download in bytes.
progressnumberTotal bytes processed from network requests. May decrease after pausing since unwritten data is discarded and some progress is lost.
chunkProgressnumberTotal bytes written to disk. May decrease when a file fails and partial chunk progress is lost.
fileProgressnumberTotal bytes from fully downloaded files.
totalFilesnumberNumber of files included in the transfer.
finalizedFilesnumberNumber of successfully downloaded files.

Subscribe to events using the on() method. Attach callbacks before calling start().

downloader.on(Downloader.DownloaderEvents.Progress, ({ data }) => {
console.log("Progress:", data.performanceStats);
});

The downloader emits state change events as it transitions through the download lifecycle:

ConstantDescription
DownloadingThe downloader is actively downloading files.
PausedThe download has been paused.
CancelledThe download has been cancelled.
TerminatedThe downloader has been terminated.

States are accessed via the Downloader.States enum:

downloader.on(Downloader.States.Downloading, () => {
console.log("Downloading");
});
ConstantString ValueDataDescription
Abortdownload:abortfileId: stringThe download has been aborted after pausing or cancelling the transfer.
Errordownload:errorperformanceStats: PerformanceResults; error: ErrorAn error has occurred with the downloader. The download cannot continue.
FileDownloadeddownload:file-downloadedfileId: stringA file has been successfully downloaded.
FileErroreddownload:file-erroredfileId: string; error: ErrorAn error has occurred downloading a specific file. Errored files are automatically skipped, allowing the download to continue.
FileQueueddownload:file-queuedfileId: stringA file has been queued for download.
Finisheddownload:finishperformanceStats: PerformanceResultsAll files have been successfully downloaded.
ParentDirectoryCreateddownload:parent-directory-createdparentDirectoryName: stringA parent directory named after the Package has been created. This happens before any files are downloaded.
PartialFinisheddownload:partial-finishperformanceStats: PerformanceResults; failedFiles: BaseFile[]One or more files failed during download. The affected files were skipped and the rest of the download completed successfully. Errored files can be retried with retry().
Progressdownload:progressperformanceStats: PerformanceResultsDownload progress report.
Retrydownload:retryperformanceStats: PerformanceResults; error: ErrorThe downloader is retrying a request, usually due to a network issue.

Events are accessed via the Downloader.DownloaderEvents enum:

Downloader.DownloaderEvents.Progress // "download:progress"
Downloader.DownloaderEvents.Finished // "download:finish"
Downloader.DownloaderEvents.Error // "download:error"
// ... etc.