microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.11.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/networkInspector/requestBodyFormatters/utils.ts

40lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4/* eslint-disable */
5/* eslint-enable prettier/prettier*/
6
7import { TextDecoder } from "util";
8import { Base64 } from "js-base64";
9
10/**
11 * @preserve
12 * Start region: the code is borrowed from https://github.com/facebook/flipper/blob/v0.79.1/desktop/plugins/network/chunks.tsx#L12-L28
13 *
14 * Copyright (c) Facebook, Inc. and its affiliates.
15 *
16 * This source code is licensed under the MIT license found in the
17 * LICENSE file in the root directory of this source tree.
18 *
19 * @format
20 */
21
22export function combineBase64Chunks(chunks: string[]): string {
23 const byteArray = chunks.map(
24 b64Chunk => Uint8Array.from(Base64.atob(b64Chunk), c => c.charCodeAt(0)).buffer,
25 );
26 const size = byteArray.map(b => b.byteLength).reduce((prev, curr) => prev + curr, 0);
27 const buffer = new Uint8Array(size);
28 let offset = 0;
29 for (let i = 0; i < byteArray.length; i++) {
30 buffer.set(new Uint8Array(byteArray[i]), offset);
31 offset += byteArray[i].byteLength;
32 }
33 const data = new TextDecoder("utf-8").decode(buffer);
34 return data;
35}
36
37/**
38 * @preserve
39 * End region: https://github.com/facebook/flipper/blob/v0.79.1/desktop/plugins/network/chunks.tsx#L12-L28
40 */
41