MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / download

Function download

scripts/npm-shim.js:190–214  ·  view source on GitHub ↗
(url, dest, redirectsLeft)

Source from the content-addressed store, hash-verified

188
189// GET with manual redirect following (GitHub release URLs redirect to a CDN).
190function download(url, dest, redirectsLeft) {
191 return new Promise(function (resolve, reject) {
192 var https = require('https');
193 // timeout is an idle/inactivity timeout — it won't kill a slow-but-progressing
194 // download, only a stalled connection (so a blocked mirror fails fast with
195 // guidance instead of hanging the user's command forever).
196 var req = https.get(url, { headers: { 'User-Agent': 'codegraph-npm-shim' }, timeout: 30000 }, function (res) {
197 var status = res.statusCode;
198 if (status >= 300 && status < 400 && res.headers.location) {
199 res.resume();
200 if (redirectsLeft <= 0) { reject(new Error('too many redirects')); return; }
201 download(new URL(res.headers.location, url).toString(), dest, redirectsLeft - 1).then(resolve, reject);
202 return;
203 }
204 if (status !== 200) { res.resume(); reject(new Error('HTTP ' + status)); return; }
205 var file = fs.createWriteStream(dest);
206 res.on('error', reject);
207 res.pipe(file);
208 file.on('error', reject);
209 file.on('finish', function () { file.close(function () { resolve(); }); });
210 });
211 req.on('timeout', function () { req.destroy(new Error('connection timed out')); });
212 req.on('error', reject);
213 });
214}
215
216// Best-effort integrity check. When the release publishes a SHA256SUMS file, the
217// downloaded archive MUST match its listed hash or we abort. When that file is

Callers 2

selfHealBundleFunction · 0.70
verifyChecksumFunction · 0.70

Calls 6

resumeMethod · 0.80
getMethod · 0.65
onMethod · 0.65
closeMethod · 0.65
resolveFunction · 0.50
destroyMethod · 0.45

Tested by

no test coverage detected