var downloadArchive = function()

in node/buildutils.js [90:136]


var downloadArchive = function (url) {
    // validate platform
    var platform = os.platform();
    if (platform != 'darwin' && platform != 'linux') {
        throw new Error('Unexpected platform: ' + platform);
    }

    // validate parameters
    if (!url) {
        throw new Error('Parameter "url" must be set.');
    }

    if (!url.match(/\.tar\.gz$/)) {
        throw new Error('Expected .tar.gz');
    }

    // short-circuit if already downloaded and extracted
    var scrubbedUrl = url.replace(/[/\:?]/g, '_');
    var targetPath = path.join(downloadPath, 'archive', scrubbedUrl);
    var marker = targetPath + '.completed';
    if (!test('-f', marker)) {
        // download the archive
        var archivePath = downloadFile(url);
        console.log('Extracting archive: ' + url);

        // delete any previously attempted extraction directory
        if (test('-d', targetPath)) {
            rm('-rf', targetPath);
        }

        // extract
        mkdir('-p', targetPath);
        var cwd = process.cwd();
        process.chdir(targetPath);
        try {
            run('tar -xzf "' + archivePath + '"');
        }
        finally {
            process.chdir(cwd);
        }

        // write the completed marker
        fs.writeFileSync(marker, '');
    }

    return targetPath;
}