jszip
jszip copied to clipboard
docx.Packer.toBuffer returns uint8Array and not Buffer in node
Hi
I run this code. Generating a buffer and and writing it with express as a downloadable file.
const buffer = await docx.Packer.toBuffer(doc)
console.log(Buffer.isBuffer(buffer))
res.status(200).end(buffer)
However the generated buffer is really an uint8Array (and Buffer.isBuffer writes false) so the res.end call fails with the following error:
2020-05-12 00:12:07 TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer. Received an instance of Buffer
at ServerResponse.end (_http_outgoing.js:753:13)
... call stack for my application removed...
If I however changes the array to a buffer with Buffer.from is everything working and Buffer.isBuffer returns true
const arr = await docx.Packer.toBuffer(doc)
const buffer = Buffer.from(arr)
console.log(Buffer.isBuffer(buffer))
res.status(200).end(buffer)
Hello how are you? . I would like to thank you. You solved a problem I was having.