MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / downloadFile

Function downloadFile

scripts/download-node.mjs:116–139  ·  view source on GitHub ↗
(url, dest)

Source from the content-addressed store, hash-verified

114// ── HTTP helpers ─────────────────────────────────────────────────────────────
115
116function downloadFile(url, dest) {
117 return new Promise((resolve, reject) => {
118 const file = createWriteStream(dest);
119 function doGet(u) {
120 get(u, { headers: { "User-Agent": "agent-canvas-build" } }, (res) => {
121 if (res.statusCode === 301 || res.statusCode === 302) {
122 return doGet(res.headers.location);
123 }
124 if (res.statusCode !== 200) {
125 file.destroy();
126 return reject(new Error(`GET ${u} → HTTP ${res.statusCode}`));
127 }
128 res.pipe(file);
129 file.on("finish", () => file.close(resolve));
130 file.on("error", reject);
131 res.on("error", reject);
132 }).on("error", (err) => {
133 file.destroy();
134 reject(err);
135 });
136 }
137 doGet(url);
138 });
139}
140
141// ── Extraction ───────────────────────────────────────────────────────────────
142

Callers 1

mainFunction · 0.70

Calls 1

doGetFunction · 0.70

Tested by

no test coverage detected