Skip to content

Commit 03cefd7

Browse files
committed
Add missing Uint8Array methods for dealing with base64 and hex content
1 parent b941efa commit 03cefd7

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

externs/es6.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,72 @@ Int8Array.from = function(source, mapFn, thisArg) {};
808808
Int8Array.of = function(var_args) {};
809809

810810

811+
/**
812+
* Options to use when decoding base64 into a Uint8Array.
813+
* @record
814+
*/
815+
function Uint8ArrayBase64Options() {}
816+
817+
/**
818+
* Specifies the base64 alphabet to use. This can either be "base64", which will include the special characters `+`
819+
* and `/`, or "base64url", which will include the special characters `-` and `_`. If not specified, it defaults to
820+
* "base64".
821+
* @type {(undefined|string)}
822+
*/
823+
Uint8ArrayBase64Options.prototype.alphabet;
824+
825+
/**
826+
* Specifies how to handle the last chunk of the base64 string if it is an incomplete chunk. The value "strict" requires
827+
* that any incomplete chunk be padded with `=` characters and any trailing bits must be zero. The value
828+
* "stop-before-partial" indicates that decoding should only handle complete chunks and ignore partial chunks, allowing
829+
* them to be handled separately if desired (such as in future calls). The default value is "loose", which will decode
830+
* an incomplete chunk even if not padded by `=`.
831+
* @type {(undefined|string)}
832+
*/
833+
Uint8ArrayBase64Options.prototype.lastChunkHandling;
834+
835+
836+
/**
837+
* Results from Uint8Array.prototype.setFromBase64.
838+
* @record
839+
*/
840+
function Uint8ArraySetFromBase64Results() {}
841+
842+
/**
843+
* The number of characters read from the base64 string. If the entire string's contents fit into the Uint8Array,
844+
* this will be equal to string.length. Otherwise, this will be equal to the number of 4-character chunks that
845+
* fit into the array.
846+
* @type {number}
847+
*/
848+
Uint8ArraySetFromBase64Results.prototype.read;
849+
850+
/**
851+
* The number of bytes written into the Uint8Array.
852+
* @type {number}
853+
*/
854+
Uint8ArraySetFromBase64Results.prototype.written;
855+
856+
/**
857+
* Options to use when invoking Uint8Array.prototype.toBase64.
858+
* @record
859+
*/
860+
function Uint8ArrayToBase64Options() {}
861+
862+
/**
863+
* Specifies the base64 alphabet to use. This can either be "base64", which will include the special characters `+`
864+
* and `/`, or "base64url", which will include the special characters `-` and `_`. If not specified, it defaults to
865+
* "base64".
866+
* @type {(undefined|string)}
867+
*/
868+
Uint8ArrayToBase64Options.prototype.alphabet;
869+
870+
/**
871+
* If true, the output base64 string will omit any `=` padding characters at the end. Defaults to false.
872+
* @type {(undefined|boolean)}
873+
*/
874+
Uint8ArrayToBase64Options.prototype.omitPadding;
875+
876+
811877
/**
812878
* @param {number|ArrayBufferView|Array<number>|ArrayBuffer|SharedArrayBuffer}
813879
* length or array or buffer
@@ -844,6 +910,41 @@ Uint8Array.from = function(source, mapFn, thisArg) {};
844910
*/
845911
Uint8Array.of = function(var_args) {};
846912

913+
/**
914+
* Creates a new Uint8Array from a base64 encoded string.
915+
* @param {!string} string a base64 string encoded array
916+
* @param {Uint8ArrayBase64Options=} options an object specifying how to read the base64 string
917+
* @return {!Uint8Array} a newly created array with the specified bytes
918+
*/
919+
Uint8Array.fromBase64 = function(string, options) {};
920+
921+
/**
922+
* Creates a new Uint8Array from a case-insensitive hex string with even length.
923+
* @param {!string} string a hex string encoded array of bytes
924+
* @return {!Uint8Array} a newly created array with the specified bytes
925+
*/
926+
Uint8Array.fromHex = function(string) {};
927+
928+
/**
929+
* Sets the contents of the Uint8Array from a base64 encoded string.
930+
* @param {!string} string a base64 string encoded array to write into this array
931+
* @param {Uint8ArrayBase64Options=} options an object specifying how to read the base64 string
932+
* @return {!Uint8ArraySetFromBase64Results} results about the operation
933+
*/
934+
Uint8Array.prototype.setFromBase64 = function(string, options) {};
935+
936+
/**
937+
* Encodes the contents of the Uint8Array into a base64 string.
938+
* @param {Uint8ArrayToBase64Options=} options an object specifying how to encode the base64 string
939+
* @return {!string} a base64 encoded string representing the contents of this array
940+
*/
941+
Uint8Array.prototype.toBase64 = function(options) {};
942+
943+
/**
944+
* Encodes the contents of the Uint8Array into a hex string.
945+
* @return {!string} a hex encoded string representing the contents of this array
946+
*/
947+
Uint8Array.prototype.toHex = function() {};
847948

848949
/**
849950
* @param {number|ArrayBufferView|Array<number>|ArrayBuffer|SharedArrayBuffer}

0 commit comments

Comments
 (0)