1 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
|
3 | /**
|
4 | * Encodes a string in base64 format.
|
5 | * @param value the string to encode
|
6 | */
|
7 | export function encodeString(value) {
|
8 | return btoa(value);
|
9 | }
|
10 | /**
|
11 | * Encodes a byte array in base64 format.
|
12 | * @param value the Uint8Aray to encode
|
13 | */
|
14 | export function encodeByteArray(value) {
|
15 | var str = "";
|
16 | for (var i = 0; i < value.length; i++) {
|
17 | str += String.fromCharCode(value[i]);
|
18 | }
|
19 | return btoa(str);
|
20 | }
|
21 | /**
|
22 | * Decodes a base64 string into a byte array.
|
23 | * @param value the base64 string to decode
|
24 | */
|
25 | export function decodeString(value) {
|
26 | var byteString = atob(value);
|
27 | var arr = new Uint8Array(byteString.length);
|
28 | for (var i = 0; i < byteString.length; i++) {
|
29 | arr[i] = byteString.charCodeAt(i);
|
30 | }
|
31 | return arr;
|
32 | }
|
33 | //# sourceMappingURL=base64.browser.js.map |
\ | No newline at end of file |