MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / pipeRequest

Function pipeRequest

framework/utils/lib/utils.ts:341–367  ·  view source on GitHub ↗
(req: superagent.Request, w: fs.WriteStream, timeout?: number, name?: string)

Source from the content-addressed store, hash-verified

339}
340
341export async function pipeRequest(req: superagent.Request, w: fs.WriteStream, timeout?: number, name?: string) {
342 try {
343 await new Promise((resolve, reject) => {
344 w.on('finish', () => {
345 resolve(null);
346 });
347 req.buffer(false).timeout({
348 response: Math.min(10000, timeout),
349 deadline: timeout,
350 }).parse((resp, cb) => {
351 if (resp.statusCode !== 200) throw new Error(`${resp.statusCode}`);
352 else {
353 resp.pipe(w);
354 resp.on('end', () => {
355 cb(null, undefined);
356 });
357 resp.on('error', (err) => {
358 cb(err, undefined);
359 reject(err);
360 });
361 }
362 }).catch(reject);
363 });
364 } catch (e: any) {
365 throw new Error(`Download${e.errno === 'ETIMEDOUT' ? 'Timedout' : 'Error'}(${name ? `${name}, ` : ''}${e.message})`);
366 }
367}
368
369export * as yaml from 'js-yaml';

Callers 4

getFileFunction · 0.90
problemDataMethod · 0.90
recordPretestDataMethod · 0.90
fetchFileMethod · 0.90

Calls 3

resolveFunction · 0.85
cbFunction · 0.50
onMethod · 0.45

Tested by

no test coverage detected