Use persistent HTTP connection to the registry
This commit is contained in:
@ -1,7 +1,4 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fetch = require("isomorphic-fetch");
|
|
||||||
const gunzip = require("gunzip-maybe");
|
|
||||||
const tar = require("tar-stream");
|
|
||||||
|
|
||||||
const addLeadingSlash = require("../utils/addLeadingSlash");
|
const addLeadingSlash = require("../utils/addLeadingSlash");
|
||||||
const createPackageURL = require("../utils/createPackageURL");
|
const createPackageURL = require("../utils/createPackageURL");
|
||||||
|
|||||||
@ -1,13 +1,31 @@
|
|||||||
const fetch = require("isomorphic-fetch");
|
const url = require("url");
|
||||||
|
const https = require("https");
|
||||||
const gunzip = require("gunzip-maybe");
|
const gunzip = require("gunzip-maybe");
|
||||||
const tar = require("tar-stream");
|
const tar = require("tar-stream");
|
||||||
|
|
||||||
function fetchArchive(packageConfig) {
|
const agent = new https.Agent({
|
||||||
const tarballURL = packageConfig.dist.tarball;
|
keepAlive: true
|
||||||
|
});
|
||||||
|
|
||||||
return fetch(tarballURL).then(res =>
|
function fetchArchive(packageConfig) {
|
||||||
res.body.pipe(gunzip()).pipe(tar.extract())
|
return new Promise((resolve, reject) => {
|
||||||
);
|
const tarballURL = url.parse(packageConfig.dist.tarball);
|
||||||
|
const options = {
|
||||||
|
hostname: tarballURL.hostname,
|
||||||
|
path: tarballURL.pathname,
|
||||||
|
agent: agent
|
||||||
|
};
|
||||||
|
|
||||||
|
https
|
||||||
|
.get(options, res => {
|
||||||
|
if (res.statusCode === 200) {
|
||||||
|
resolve(res.pipe(gunzip()).pipe(tar.extract()));
|
||||||
|
} else {
|
||||||
|
reject(res);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on("error", reject);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = fetchArchive;
|
module.exports = fetchArchive;
|
||||||
|
|||||||
Reference in New Issue
Block a user