mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-10 05:35:05 +08:00
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>
37 lines
1.4 KiB
JavaScript
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;
|
|
}
|