Module: siteKiosk.network.fileDownload

This module provides the possibility to download files to the file system. It can be used for example to build a local file cache or to let the user download files. The download function expects a callback and returns a download handle that can be used to cancel the download or to query its progress percentage. There are also functions to retrieve information about current downloads and to remove downloads based on some url criteria. The module uses a status from the 'status' member below to identify the status of a download.

Example

//we have no cookie, so we pass in null
var downloadHandle = siteKiosk.network.fileDownload.download(
                         "http//your.url",
                         "/some/local/path",
                         null,
                         function(status, localFileName, mediaType) {
                             //hopefully status = 8, which represents success (see status table)
                             console.log("Download finished with status "+status);
                         }
                     );

//after one second, log the download's progress percentage
setTimeout(function() {
     console.log("Download is at "+downloadHandle.getProgress()+" %.");
}, 1000;

Members

<static> status :number

Download status.
Type:
  • number
Properties:
Name Type Default Description
pending number 1
running number 2
paused number 4
success number 8
failed number 16
unknown number -1

Methods

<static> download(url, path, cookieString, completed) → {siteKiosk.network.fileDownload~downloadHandle}

Starts a file download.
Parameters:
Name Type Argument Description
url string The URL to the resource, which should be downloaded
path string <nullable>
The destination file path
cookieString string <nullable>
The Cookie HTTP header
completed siteKiosk.network.fileDownload~downloadCallback A callback, which will be called when the download is complete
Returns:
A handle to cancel the download
Type
siteKiosk.network.fileDownload~downloadHandle

<static> getStatus(url) → {number}

Gets the download status for a given URL.
Parameters:
Name Type Description
url string The download URl
Returns:
The download status
Type
number

<static> removeDownloadByUrlPrefix(urlPrefix, completed)

Removes all downloads whose source URL starts with the given URL prefix.
Parameters:
Name Type Description
urlPrefix string The URL prefix
completed siteKiosk.network.fileDownload~removeDownloadCallback The callback which will be called when the operation has been completed

Type Definitions

downloadCallback(status, localFileName, mediaType)

A callback which will be called when a download has been finished.
Parameters:
Name Type Description
status string The download status (either "success" or "failed")
localFileName string The path to the file
mediaType string The MIME type of the downloaded file

downloadHandle

A handle to cancel the download.
Properties:
Name Type Description
cancel function Function to cancel the download
getProgress function Function to get the progress of the download (in percent)

removeDownloadCallback()

A callback which will be called when an operation to remove downloads has been completed.