nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Binary/Buffer support for workers

Open pi0 opened this issue 2 years ago • 1 comments

Context: https://github.com/nuxt/framework/issues/3982

Relevant upstream improvement: https://github.com/unjs/unenv/issues/23

pi0 avatar Apr 12 '22 17:04 pi0

Blob is supported in unenv. @danielroe Can you please verify it?

pi0 avatar May 05 '22 21:05 pi0

Looking for docs on how to send binary file, but found nothing. Don't forgot to mention it in docs, please. :-)

iBobik avatar Jan 08 '24 17:01 iBobik

How I did it:

setHeader(handler, 'Content-Type', 'application/pdf')
return sendStream(handler, Readable.from(Buffer.from(pdfBase64, 'base64')))

iBobik avatar Jan 09 '24 00:01 iBobik

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 👍🏼

pi0 avatar Jan 16 '24 13:01 pi0