Files
react-native-devtools-frontend/front_end/common/Base64.js
T
Sigurd Schneider db13439afe Add IOModel to Browser, Frame, and worker targets
This makes it possible to use the IO domain to retrieve data from
stream handles of the IO domain.

Corresponding back-end CL:
https://crrev.com/c/2421369

Bug: chromium:1069378
Change-Id: I1c6633c43ea35da5b4a2302f1356ba3e565f3683
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2422959
Reviewed-by: Philip Pfaffe <pfaffe@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
2020-09-23 09:35:14 +00:00

37 lines
1.4 KiB
JavaScript

// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
const BASE64_CODES = new Uint8Array(123);
for (let index = 0; index < BASE64_CHARS.length; ++index) {
BASE64_CODES[BASE64_CHARS.charCodeAt(index)] = index;
}
/**
* Decodes Base64-encoded data from a string without performing any kind of checking.
*
* @param {string} input valid Base64-encoded data
* @return {!ArrayBuffer} decoded result
*/
export function decode(input) {
let bytesLength = ((input.length * 3) / 4) >>> 0;
if (input.charCodeAt(input.length - 2) === 0x3d /* '=' */) {
bytesLength -= 2;
} else if (input.charCodeAt(input.length - 1) === 0x3d /* '=' */) {
bytesLength -= 1;
}
const bytes = new Uint8Array(bytesLength);
for (let index = 0, offset = 0; index < input.length; index += 4) {
const a = BASE64_CODES[input.charCodeAt(index + 0)];
const b = BASE64_CODES[input.charCodeAt(index + 1)];
const c = BASE64_CODES[input.charCodeAt(index + 2)];
const d = BASE64_CODES[input.charCodeAt(index + 3)];
bytes[offset++] = (a << 2) | (b >> 4);
bytes[offset++] = ((b & 0x0f) << 4) | (c >> 2);
bytes[offset++] = ((c & 0x03) << 6) | (d & 0x3f);
}
return bytes.buffer;
}