Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFWorkers / Oxygen support #3

Closed
frehner opened this issue Mar 24, 2023 · 1 comment · Fixed by #9
Closed

CFWorkers / Oxygen support #3

frehner opened this issue Mar 24, 2023 · 1 comment · Fixed by #9

Comments

@frehner
Copy link

frehner commented Mar 24, 2023

Hello, I'm testing this out in a Cloudflare Workers-like environment (Oxygen 🙂 ) and unfortunately Buffer isn't supported there. I receive the error:

Error: Buffer is not globally defined in this environment. Consider setting useTArray to true
at Object.format [as jpg] (/node_modules/jpeg-js/lib/decoder.js:1141:15)

The good news is, if I only work with jpgs, I can modify this line

return decoders[format](imageData);

to the following code

decoders[format](imageData, {useTArray: true});

which bypasses using a Buffer and uses Uint8Array directly, which is supported in CFWorkers! Docs on that option https://github.com/jpeg-js/jpeg-js#decode-options

So somehow I need the ability to pass that useTArray option to jpeg-js and thing seem to work from there. (For jpegs at least. I don't think they work for pngs, but I'm haven't looked into that, yet.)

@ascorbic
Copy link
Owner

I think this should work now, for both JPEG (because of the useTArray trick) and PNG because it shims global Buffer with an import from "node:buffer". This should work on most edge runtimes now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants