Stream response #157
-
Hi folks. |
Beta Was this translation helpful? Give feedback.
Answered by
franciscop
Aug 29, 2024
Replies: 1 comment 2 replies
-
Thanks for asking! Sure, there are multiple ways, please see this comment: // Streaming a file:
const { file } = require('server/reply');
const mid = () => file("./path/myfile.mp3"); For arbitrary data: // Untested, but you might/should be able to stream like this:
const { pipeline } = require('node:stream/promises');
const mid = async (ctx) => {
ctx.res.setHeader('Content-Type', 'audio/mp3');
await pipeline(nodeReadStream, ctx.res);
}; // If the above didn't work, this is verified to work:
const mid = (ctx) => {
ctx.res.setHeader('Content-Type', 'audio/mp3');
return new Promise((resolve) => {
nodeReadStream.pipe(ctx.res).on('end', resolve);
});
}; |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
lantica
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for asking! Sure, there are multiple ways, please see this comment:
For arbitrary data: