(req: superagent.Request, w: fs.WriteStream, timeout?: number, name?: string)
| 339 | } |
| 340 | |
| 341 | export 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 | |
| 369 | export * as yaml from 'js-yaml'; |
no test coverage detected