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

Fix base64 code example #32518

Merged
merged 4 commits into from
Mar 3, 2024
Merged

Fix base64 code example #32518

merged 4 commits into from
Mar 3, 2024

Conversation

Zwyx
Copy link
Contributor

@Zwyx Zwyx commented Mar 2, 2024

Description

Fix error in bytesToBase64 code example

Using fromCodePoint(...bytes) leads to the error RangeError: Maximum call stack size exceeded when bytes is long (it happens with 150k bytes for me with Chrome 122 on Linux).

Using Array.from fixes this issue.

Mention that FileReader and fetch offer better performances

Motivation

Prevent developers from using a piece of code that gives the impression it's working, but might fail later if used with long data.

Additional details

Error in Chrome 122 on Linux when calling bytesToBase64 with an argument of size 150k:

image

Related issues and pull requests

N/A

Zwyx added 2 commits March 2, 2024 10:57
Using `fromCodePoint(...bytes)` leads to the error `RangeError: Maximum call stack size exceeded` when `bytes` is long (it happens with 150k bytes for me with Chrome 122 on Linux).

Using `Array.from` fixes this issue.
@Zwyx Zwyx requested a review from a team as a code owner March 2, 2024 04:16
@Zwyx Zwyx requested review from chrisdavidmills and removed request for a team March 2, 2024 04:16
@github-actions github-actions bot added Content:Glossary Glossary entries size/xs [PR only] 0-5 LoC changed labels Mar 2, 2024
Copy link
Contributor

github-actions bot commented Mar 2, 2024

Preview URLs

(comment last updated: 2024-03-03 05:36:23)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot added size/s [PR only] 6-50 LoC changed and removed size/xs [PR only] 0-5 LoC changed labels Mar 2, 2024
Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Nice seeing you here ;)

@Josh-Cena Josh-Cena merged commit 45421b1 into mdn:main Mar 3, 2024
9 checks passed
@Zwyx
Copy link
Contributor Author

Zwyx commented Mar 3, 2024

Oh hi! Great seeing you here too! Thanks for the fix and the merge 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:Glossary Glossary entries size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants