src/extensibility/node/ExtensionManagerDomain.js
function _cmdDownloadFile(downloadId, url, proxy, callback, pCallback) {
    // Backwards compatibility check, added in 0.37
    if (typeof proxy === "function") {
        callback = proxy;
        proxy = undefined;
    }

    if (pendingDownloads[downloadId]) {
        callback(Errors.DOWNLOAD_ID_IN_USE, null);
        return;
    }

    var req = request.get({
        url: url,
        encoding: null,
        proxy: proxy
    },
        // Note: we could use the traditional "response"/"data"/"end" events too if we wanted to stream data
        // incrementally, limit download size, etc. - but the simple callback is good enough for our needs.
        function (error, response, body) {
            if (error) {
                // Usually means we never got a response - server is down, no DNS entry, etc.
                _endDownload(downloadId, Errors.NO_SERVER_RESPONSE);
                return;
            }
            if (response.statusCode !== 200) {
                _endDownload(downloadId, [Errors.BAD_HTTP_STATUS, response.statusCode]);
                return;
            }

            var stream = temp.createWriteStream("brackets");
            if (!stream) {
                _endDownload(downloadId, Errors.CANNOT_WRITE_TEMP);
                return;
            }
            pendingDownloads[downloadId].localPath = stream.path;
            pendingDownloads[downloadId].outStream = stream;

            stream.write(body);
            _endDownload(downloadId);
        });

    pendingDownloads[downloadId] = { request: req, callback: callback };
}
function _cmdDownloadFile(downloadId, url, proxy, callback, pCallback) {
    // Backwards compatibility check, added in 0.37
    if (typeof proxy === "function") {
        callback = proxy;
        proxy = undefined;
    }

    if (pendingDownloads[downloadId]) {
        callback(Errors.DOWNLOAD_ID_IN_USE, null);
        return;
    }

    var req = request.get({
        url: url,
        encoding: null,
        proxy: proxy
    },
        // Note: we could use the traditional "response"/"data"/"end" events too if we wanted to stream data
        // incrementally, limit download size, etc. - but the simple callback is good enough for our needs.
        function (error, response, body) {
            if (error) {
                // Usually means we never got a response - server is down, no DNS entry, etc.
                _endDownload(downloadId, Errors.NO_SERVER_RESPONSE);
                return;
            }
            if (response.statusCode !== 200) {
                _endDownload(downloadId, [Errors.BAD_HTTP_STATUS, response.statusCode]);
                return;
            }

            var stream = temp.createWriteStream("brackets");
            if (!stream) {
                _endDownload(downloadId, Errors.CANNOT_WRITE_TEMP);
                return;
            }
            pendingDownloads[downloadId].localPath = stream.path;
            pendingDownloads[downloadId].outStream = stream;

            stream.write(body);
            _endDownload(downloadId);
        });

    pendingDownloads[downloadId] = { request: req, callback: callback };
}
function _cmdDownloadFile ( downloadId , url , proxy , callback , pCallback ) { // Backwards compatibility check, added in 0.37 if ( typeof proxy === "function" ) { callback = proxy ; proxy = undefined ; } if ( pendingDownloads [ downloadId ] ) { callback ( Errors . DOWNLOAD_ID_IN_USE , null ) ; return ; } var req = request . get ( { url : url , encoding : null , proxy : proxy } , // Note: we could use the traditional "response"/"data"/"end" events too if we wanted to stream data // incrementally, limit download size, etc. - but the simple callback is good enough for our needs. function ( error , response , body ) { if ( error ) { // Usually means we never got a response - server is down, no DNS entry, etc. _endDownload ( downloadId , Errors . NO_SERVER_RESPONSE ) ; return ; } if ( response . statusCode !== 200 ) { _endDownload ( downloadId , [ Errors . BAD_HTTP_STATUS , response . statusCode ] ) ; return ; } var stream = temp . createWriteStream ( "brackets" ) ; if ( ! stream ) { _endDownload ( downloadId , Errors . CANNOT_WRITE_TEMP ) ; return ; } pendingDownloads [ downloadId ] . localPath = stream . path ; pendingDownloads [ downloadId ] . outStream = stream ; stream . write ( body ) ; _endDownload ( downloadId ) ; } ) ; pendingDownloads [ downloadId ] = { request : req , callback : callback } ; }
Implements "downloadFile" command, asynchronously.
Implements downloadFile command asynchronously .