"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const https_1 = require("https");
const Url = require("url");
exports.STARTER_BASE_URL = 'https://s3.eu-west-2.amazonaws.com/emu-flo.w/starters';
function downloadStarter(starter) {
    return downloadFromURL(`${exports.STARTER_BASE_URL}/${starter.repo}`);
}
exports.downloadStarter = downloadStarter;
function downloadFromURL(url) {
    const options = Url.parse(url);
    return new Promise((resolve, reject) => {
        https_1.get(options, res => {
            if (res.statusCode === 302) {
                downloadFromURL(res.headers.location).then(resolve, reject);
            }
            else {
                const data = [];
                res.on('data', chunk => data.push(chunk));
                res.on('end', () => {
                    resolve(Buffer.concat(data));
                });
                res.on('error', reject);
            }
        });
    });
}
//# sourceMappingURL=download.js.map