microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.6.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/networkInspector/requestBodyFormatters/utils.ts

37lines · modeblame

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