main
js 33 lines 727 Bytes
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 import {TextDecoder} from 'util';
11
12 export type StringDecoder = TextDecoder;
13
14 export function createStringDecoder(): StringDecoder {
15 return new TextDecoder();
16 }
17
18 const decoderOptions = {stream: true};
19
20 export function readPartialStringChunk(
21 decoder: StringDecoder,
22 buffer: Uint8Array,
23 ): string {
24 // $FlowFixMe[incompatible-type]
25 return decoder.decode(buffer, decoderOptions);
26 }
27
28 export function readFinalStringChunk(
29 decoder: StringDecoder,
30 buffer: Uint8Array,
31 ): string {
32 return decoder.decode(buffer);
33 }