I create Excel data on the fly using Exceljs
I want to store this information in memory, and then send it to the user using Koa.
Method writefor Exceljs expects writeableStream:
workbook.xlsx.write(writableStream, options)
BUT KOA expects a readable stream:
response.body = readableStream
I know that I can transfer a readable stream to a writeable stream, but how can I do the opposite? I want Exceljs to write to a writeable stream and read Coa from one stream. I'm so upset with the threading API!
Among the 20 other things I tried this:
const ReadableStream = require("memory-streams").ReadableStream
const reader = new ReadableStream()
const writer = new stream.Writable({
write: function(chunk, encoding, next) {
console.log(chunk.toString())
next()
}
})
const reader = new MemoryStream(null, {readable: true})
const writer = reader
workbook.xlsx.write(writer, {})
return reader
But this will not work, I get some strange error in that I cannot write a thread that is closed. However, even if I handle this error, my Excel file does not open.
So how can I make a readable stream from a writeable stream?