Skip to content

Add missing Uint8Array methods for base64 and hex strings#4284

Open
niloc132 wants to merge 1 commit intogoogle:masterfrom
Vertispan:missing-uint8array-methods
Open

Add missing Uint8Array methods for base64 and hex strings#4284
niloc132 wants to merge 1 commit intogoogle:masterfrom
Vertispan:missing-uint8array-methods

Conversation

@niloc132
Copy link
Contributor

@niloc132 niloc132 commented Jan 2, 2026

No description provided.

@niloc132 niloc132 force-pushed the missing-uint8array-methods branch from 03cefd7 to 64b6c77 Compare January 2, 2026 19:39
Copy link
Contributor

@lauraharker lauraharker left a comment

Choose a reason for hiding this comment

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

Thanks! This looks great overall. I've tried pulling it into the Google repo & all our tests pass.

Just have a few small stylistic/documentation nits.

Comment on lines +915 to +917
* @param {!string} string a base64 string encoded array
* @param {Uint8ArrayBase64Options=} options an object specifying how to read the base64 string
* @return {!Uint8Array} a newly created array with the specified bytes
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the explicit ! nullability from {!string}, and add explicit nullability with ? to Uint8ArrayBase64Options.

(This is required by our internal style guide - I looked for any public wiki docs, but can't find anything... We do check for this in the linter pass in https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/lint/CheckNullabilityModifiers.java. The tl;dr, is that primitives should never have a redundant ! annotation, and all other reference types should have an explicit ? or !, since their nullability depends on whether they're a typedef/enum (non-null) or some other object (nullable by default)).

Comment on lines +924 to +949
* @param {!string} string a hex string encoded array of bytes
* @return {!Uint8Array} a newly created array with the specified bytes
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromHex
*/
Uint8Array.fromHex = function(string) {};

/**
* Sets the contents of the Uint8Array from a base64 encoded string.
* @param {!string} string a base64 string encoded array to write into this array
* @param {Uint8ArrayBase64Options=} options an object specifying how to read the base64 string
* @return {!Uint8ArraySetFromBase64Results} results about the operation
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/setFromBase64
*/
Uint8Array.prototype.setFromBase64 = function(string, options) {};

/**
* Encodes the contents of the Uint8Array into a base64 string.
* @param {Uint8ArrayToBase64Options=} options an object specifying how to encode the base64 string
* @return {!string} a base64 encoded string representing the contents of this array
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64
*/
Uint8Array.prototype.toBase64 = function(options) {};

/**
* Encodes the contents of the Uint8Array into a hex string.
* @return {!string} a hex encoded string representing the contents of this array
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments on ! and ? for these parameter types



/**
* Options to use when decoding base64 into a Uint8Array.
Copy link
Contributor

Choose a reason for hiding this comment

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

Optionally - consider linking to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64#options & the other options descriptions for the other records

@niloc132
Copy link
Contributor Author

niloc132 commented Jan 9, 2026

Thank you for the review, I'll try to turn this around promptly.

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 this pull request may close these issues.

2 participants