microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/extension/networkInspector/requestBodyFormatters/utils.ts
37lines · 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 | import { TextDecoder } from "util"; |
| 5 | import { 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 | |
| 19 | export function combineBase64Chunks(chunks: string[]): string { |
| 20 | const byteArray = chunks.map( |
| 21 | b64Chunk => Uint8Array.from(Base64.atob(b64Chunk), c => c.charCodeAt(0)).buffer, |
| 22 | ); |
| 23 | const size = byteArray.map(b => b.byteLength).reduce((prev, curr) => prev + curr, 0); |
| 24 | const buffer = new Uint8Array(size); |
| 25 | let offset = 0; |
| 26 | for (let i = 0; i < byteArray.length; i++) { |
| 27 | buffer.set(new Uint8Array(byteArray[i]), offset); |
| 28 | offset += byteArray[i].byteLength; |
| 29 | } |
| 30 | const data = new TextDecoder("utf-8").decode(buffer); |
| 31 | return 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 | */ |
| 38 | |