admin管理员组文章数量:1302379
I have a problem with next.js and PDFKit stream. When I create new PDFDocument, convert the stream into new Readable stream and push the data to response, client receives data when doc.end() is fired even though readableStream receives data immediately.
function convertStream(data: any): ReadableStream {
const readableStream = new ReadableStream({
start(controller) {
data.on("data", (chunk: any) => {
controller.enqueue(chunk);
});
data.on("end", () => {
controller.close();
});
data.on("error", (err: Error) => {
controller.error(err);
});
},
cancel() {
data.end();
},
});
return readableStream;
}
const doc = new PDFDocument();
const stream = convertStream(doc);
//doc content
doc.end();
return new Response(stream, headers);
When I use the same convert function on fs.createReadStream data is pushed to client right away. Please help.
本文标签: Nextjs and PDFKit stream to response problemStack Overflow
版权声明:本文标题:Next.js and PDFKit stream to response problem - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741691081a2392725.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论