mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
utils: fix pipeRequest
This commit is contained in:
1 file changed
+17
-14
+17
-14
@@ -325,20 +325,23 @@ export async function extractZip(zip: AdmZip, dest: string, overwrite = false, s
|
|||||||
|
|
||||||
export async function pipeRequest(req: superagent.Request, w: fs.WriteStream, timeout?: number, name?: string) {
|
export async function pipeRequest(req: superagent.Request, w: fs.WriteStream, timeout?: number, name?: string) {
|
||||||
try {
|
try {
|
||||||
await req.buffer(false).timeout({
|
await new Promise((resolve, reject) => {
|
||||||
response: Math.min(10000, timeout),
|
req.buffer(false).timeout({
|
||||||
deadline: timeout,
|
response: Math.min(10000, timeout),
|
||||||
}).parse((resp, cb) => {
|
deadline: timeout,
|
||||||
if (resp.statusCode !== 200) throw new Error(`${resp.statusCode}`);
|
}).parse((resp, cb) => {
|
||||||
else {
|
if (resp.statusCode !== 200) throw new Error(`${resp.statusCode}`);
|
||||||
resp.pipe(w);
|
else {
|
||||||
resp.on('end', () => {
|
resp.pipe(w);
|
||||||
cb(null, undefined);
|
resp.on('end', () => {
|
||||||
});
|
cb(null, undefined);
|
||||||
resp.on('error', (err) => {
|
resolve(null);
|
||||||
cb(err, undefined);
|
});
|
||||||
});
|
resp.on('error', (err) => {
|
||||||
}
|
cb(err, undefined);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Download${e.errno === 'ETIMEDOUT' ? 'Timedout' : 'Error'}(${name ? `${name}, ` : ''}${e.message})`);
|
throw new Error(`Download${e.errno === 'ETIMEDOUT' ? 'Timedout' : 'Error'}(${name ? `${name}, ` : ''}${e.message})`);
|
||||||
|
|||||||
Reference in new issue
Block a user