-
Notifications
You must be signed in to change notification settings - Fork 656
feat(encoding/unstable): add format option to encodeBase64 and decodeBase64 #6457
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
Conversation
- Bring performance to stable packages - Change how the Raw encoders and decoders work to encode inline in an existing buffer
- Merged Base32, Base32Hex, and Base32Crockford into one file. - Merged Base64, and Base64Url into one file. - Added Tests for 100% coverage. - Added JSDocs
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6457 +/- ##
==========================================
+ Coverage 95.85% 95.90% +0.05%
==========================================
Files 569 572 +3
Lines 42637 42831 +194
Branches 6400 6428 +28
==========================================
+ Hits 40869 41078 +209
+ Misses 1729 1720 -9
+ Partials 39 33 -6 ☔ View full report in Codecov by Sentry. |
- Improve encoding/decoding of base64 by simplifying the maths making it a 10th of a microsecond faster and improves readability. - Reduce code and complexity to validate chars of encoded input when decoding
* assertEquals(buffer, await Deno.readFile("./deno.lock")); | ||
* ``` | ||
*/ | ||
export function decodeRawBase64( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When do you think the users would prefer this API over decodeBase64
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only real use case for this API and the encodeRawBase64
is if you're input and output is a Uint8Array
. Say you're creating a file and part of it needs to be base64 for whatever consumes it, this API lets you skip the conversion to a string and back and in the same instance use less memory.
Outside of where the encoding is embedded in other information, I doubt it would find much use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Note: This conflicts a little bit with the current convention of how to expose the variations of the same algorithm (e.g. |
Related: #6451
This pull request does three things:
encodeBase64
anddecodeBase64
that merges both Base64 and Base64Url into one with the user providing a string argument to specify which encoding/decoding they want.encodeRawBase64
anddecodeRawBase64
which is a more low level version of the previous functions meant to enable users to encode/decode part of a buffer in place.