mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
stream/internal: use pipe() to handle internal streams
This commit is contained in:
parent
fe7d4974e4
commit
85bed9aa74
1 changed files with 3 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
||||||
import { request } from 'undici';
|
import { request } from 'undici';
|
||||||
import { Readable } from 'node:stream';
|
import { Readable } from 'node:stream';
|
||||||
import { assert } from 'console';
|
import { assert } from 'console';
|
||||||
import { getHeaders } from './shared.js';
|
import { getHeaders, pipe } from './shared.js';
|
||||||
|
|
||||||
const CHUNK_SIZE = BigInt(8e6); // 8 MB
|
const CHUNK_SIZE = BigInt(8e6); // 8 MB
|
||||||
const min = (a, b) => a < b ? a : b;
|
const min = (a, b) => a < b ? a : b;
|
||||||
|
@ -66,8 +66,7 @@ async function handleYoutubeStream(streamInfo, res) {
|
||||||
if (headerValue) res.setHeader(headerName, headerValue);
|
if (headerValue) res.setHeader(headerName, headerValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.pipe(res);
|
pipe(stream, res, () => res.end());
|
||||||
stream.on('error', () => res.end());
|
|
||||||
} catch {
|
} catch {
|
||||||
res.end();
|
res.end();
|
||||||
}
|
}
|
||||||
|
@ -97,8 +96,7 @@ export async function internalStream(streamInfo, res) {
|
||||||
if (req.statusCode < 200 || req.statusCode > 299)
|
if (req.statusCode < 200 || req.statusCode > 299)
|
||||||
return res.end();
|
return res.end();
|
||||||
|
|
||||||
req.body.pipe(res);
|
pipe(req.body, res, () => res.end());
|
||||||
req.body.on('error', () => res.end());
|
|
||||||
} catch {
|
} catch {
|
||||||
streamInfo.controller.abort();
|
streamInfo.controller.abort();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue