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);
        }
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);
        }
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 ) ; }
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.
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 .
Called when the download is complete