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

Function download

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

Source from the content-addressed store, hash-verified

176
177// GET with manual redirect following (GitHub release URLs redirect to a CDN).
178function download(url, dest, redirectsLeft) {
179 return new Promise(function (resolve, reject) {
180 var https = require('https');
181 // timeout is an idle/inactivity timeout — it won't kill a slow-but-progressing
182 // download, only a stalled connection (so a blocked mirror fails fast with
183 // guidance instead of hanging the user's command forever).
184 var req = https.get(url, { headers: { 'User-Agent': 'codegraph-npm-shim' }, timeout: 30000 }, function (res) {
185 var status = res.statusCode;
186 if (status >= 300 && status < 400 && res.headers.location) {
187 res.resume();
188 if (redirectsLeft <= 0) { reject(new Error('too many redirects')); return; }
189 download(new URL(res.headers.location, url).toString(), dest, redirectsLeft - 1).then(resolve, reject);
190 return;
191 }
192 if (status !== 200) { res.resume(); reject(new Error('HTTP ' + status)); return; }
193 var file = fs.createWriteStream(dest);
194 res.on('error', reject);
195 res.pipe(file);
196 file.on('error', reject);
197 file.on('finish', function () { file.close(function () { resolve(); }); });
198 });
199 req.on('timeout', function () { req.destroy(new Error('connection timed out')); });
200 req.on('error', reject);
201 });
202}
203
204// Best-effort integrity check. When the release publishes a SHA256SUMS file, the
205// 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