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

Stop using Buffer in browser code #734

Open
jasonpaulos opened this issue Jan 14, 2023 · 3 comments
Open

Stop using Buffer in browser code #734

jasonpaulos opened this issue Jan 14, 2023 · 3 comments
Assignees

Comments

@jasonpaulos
Copy link
Contributor

Summary

We use the npm buffer package to allow our library to use node's Buffer class in the browser.

I think we should stop doing this for a few reasons:

  • buffer does not appear to be maintained anymore, as it hasn't been updated in ~2 years and has numerous issue and PRs open.
  • Webpack v4 projects provide an even older version of buffer, and we're unable to do anything about it. This is pretty concerning, as we don't test with this older version.
  • Most of our Buffer usage seems to be encoding and decoding base64. We should be able to do this in the browser without Buffer.

Suggestions

Instead of relying on a browser Buffer implementation, we could make better use of Uint8Array and Dataview, which are supported in both node and browser. Some things will still require Buffer usage in node (like base64 encoding), but we can investigate ways to have an alternative code path for browsers.

There are a few public APIs which reference Buffer, so changing these would likely have to wait for a major release of the library.

@paulmillr
Copy link

#742 doesn't use buffers

@algoanne
Copy link

Some things will still require Buffer usage in node (like base64 encoding), but we can investigate ways to have an alternative code path for browsers.

@jasonpaulos why does base64 encoding require it?

@jasonpaulos
Copy link
Contributor Author

@algoanne require is a bit of a strong word, but using Buffer for base64 encoding is likely the easiest/most efficient option for node, so that's why I suggested continuing to use it there. It is however not a strict requirement.

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

No branches or pull requests

6 participants
@winder @paulmillr @jasonpaulos @algochoi @algoanne and others