nitro
nitro copied to clipboard
Binary/Buffer support for workers
Context: https://github.com/nuxt/framework/issues/3982
Relevant upstream improvement: https://github.com/unjs/unenv/issues/23
Blob is supported in unenv. @danielroe Can you please verify it?
Looking for docs on how to send binary file, but found nothing. Don't forgot to mention it in docs, please. :-)
How I did it:
setHeader(handler, 'Content-Type', 'application/pdf')
return sendStream(handler, Readable.from(Buffer.from(pdfBase64, 'base64')))
Binary (Buffer) responses should be supported in the majority of worker providers (tests: https://github.com/unjs/nitro/pull/2078)
Re Blob support, h3 has basic support now as well as we polyfill it and recent Node.js versions have native support.
Only we might improve blob handling in h3 for metadata (https://github.com/unjs/h3/issues/619)
@iBobik Your code example seems valid. YOu can directly return a stream. Will definitely include in the upcoming docs website 👍🏼