FileTransfer.prototype.download = function()

in www/FileTransfer.js [171:221]


FileTransfer.prototype.download = function (source, target, successCallback, errorCallback, trustAllHosts, options) {
    argscheck.checkArgs('ssFF*', 'FileTransfer.download', arguments);
    const self = this;

    const basicAuthHeader = getBasicAuthHeader(source);
    if (basicAuthHeader) {
        source = source.replace(getUrlCredentials(source) + '@', '');

        options = options || {};
        options.headers = options.headers || {};
        options.headers[basicAuthHeader.name] = basicAuthHeader.value;
    }

    let headers = null;
    if (options) {
        headers = options.headers || null;
    }

    const win = function (result) {
        if (typeof result.lengthComputable !== 'undefined') {
            if (self.onprogress) {
                return self.onprogress(newProgressEvent(result));
            }
        } else if (successCallback) {
            let entry = null;
            if (result.isDirectory) {
                entry = new (require('cordova-plugin-file.DirectoryEntry'))();
            } else if (result.isFile) {
                entry = new (require('cordova-plugin-file.FileEntry'))();
            }
            entry.isDirectory = result.isDirectory;
            entry.isFile = result.isFile;
            entry.name = result.name;
            entry.fullPath = result.fullPath;
            entry.filesystem = new FileSystem(
                result.filesystemName || (result.filesystem === window.PERSISTENT ? 'persistent' : 'temporary')
            );
            entry.nativeURL = result.nativeURL;
            successCallback(entry);
        }
    };

    const fail =
        errorCallback &&
        function (e) {
            const error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body, e.exception);
            errorCallback(error);
        };

    exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id, headers]);
};