-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add missing Uint8Array methods for base64 and hex strings #4284
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -808,6 +808,72 @@ Int8Array.from = function(source, mapFn, thisArg) {}; | |
| Int8Array.of = function(var_args) {}; | ||
|
|
||
|
|
||
| /** | ||
| * Options to use when decoding base64 into a Uint8Array. | ||
| * @record | ||
| */ | ||
| function Uint8ArrayBase64Options() {} | ||
|
|
||
| /** | ||
| * Specifies the base64 alphabet to use. This can either be "base64", which will include the special characters `+` | ||
| * and `/`, or "base64url", which will include the special characters `-` and `_`. If not specified, it defaults to | ||
| * "base64". | ||
| * @type {(undefined|string)} | ||
| */ | ||
| Uint8ArrayBase64Options.prototype.alphabet; | ||
|
|
||
| /** | ||
| * Specifies how to handle the last chunk of the base64 string if it is an incomplete chunk. The value "strict" requires | ||
| * that any incomplete chunk be padded with `=` characters and any trailing bits must be zero. The value | ||
| * "stop-before-partial" indicates that decoding should only handle complete chunks and ignore partial chunks, allowing | ||
| * them to be handled separately if desired (such as in future calls). The default value is "loose", which will decode | ||
| * an incomplete chunk even if not padded by `=`. | ||
| * @type {(undefined|string)} | ||
| */ | ||
| Uint8ArrayBase64Options.prototype.lastChunkHandling; | ||
|
|
||
|
|
||
| /** | ||
| * Results from Uint8Array.prototype.setFromBase64. | ||
| * @record | ||
| */ | ||
| function Uint8ArraySetFromBase64Results() {} | ||
|
|
||
| /** | ||
| * The number of characters read from the base64 string. If the entire string's contents fit into the Uint8Array, | ||
| * this will be equal to string.length. Otherwise, this will be equal to the number of 4-character chunks that | ||
| * fit into the array. | ||
| * @type {number} | ||
| */ | ||
| Uint8ArraySetFromBase64Results.prototype.read; | ||
|
|
||
| /** | ||
| * The number of bytes written into the Uint8Array. | ||
| * @type {number} | ||
| */ | ||
| Uint8ArraySetFromBase64Results.prototype.written; | ||
|
|
||
| /** | ||
| * Options to use when invoking Uint8Array.prototype.toBase64. | ||
| * @record | ||
| */ | ||
| function Uint8ArrayToBase64Options() {} | ||
|
|
||
| /** | ||
| * Specifies the base64 alphabet to use. This can either be "base64", which will include the special characters `+` | ||
| * and `/`, or "base64url", which will include the special characters `-` and `_`. If not specified, it defaults to | ||
| * "base64". | ||
| * @type {(undefined|string)} | ||
| */ | ||
| Uint8ArrayToBase64Options.prototype.alphabet; | ||
|
|
||
| /** | ||
| * If true, the output base64 string will omit any `=` padding characters at the end. Defaults to false. | ||
| * @type {(undefined|boolean)} | ||
| */ | ||
| Uint8ArrayToBase64Options.prototype.omitPadding; | ||
|
|
||
|
|
||
| /** | ||
| * @param {number|ArrayBufferView|Array<number>|ArrayBuffer|SharedArrayBuffer} | ||
| * length or array or buffer | ||
|
|
@@ -844,6 +910,46 @@ Uint8Array.from = function(source, mapFn, thisArg) {}; | |
| */ | ||
| Uint8Array.of = function(var_args) {}; | ||
|
|
||
| /** | ||
| * Creates a new Uint8Array from a base64 encoded string. | ||
| * @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 | ||
|
Comment on lines
+915
to
+917
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the explicit (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 |
||
| * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64 | ||
| */ | ||
| Uint8Array.fromBase64 = function(string, options) {}; | ||
|
|
||
| /** | ||
| * Creates a new Uint8Array from a case-insensitive hex string with even length. | ||
| * @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 | ||
|
Comment on lines
+924
to
+949
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments on |
||
| * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex | ||
| */ | ||
| Uint8Array.prototype.toHex = function() {}; | ||
|
|
||
| /** | ||
| * @param {number|ArrayBufferView|Array<number>|ArrayBuffer|SharedArrayBuffer} | ||
|
|
||
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.
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