2018-12-01 03:38:22 +08:00
|
|
|
/**
|
2022-10-18 23:19:24 +08:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2018-12-01 03:38:22 +08:00
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
|
*
|
|
|
|
|
* @flow
|
|
|
|
|
*/
|
|
|
|
|
|
2019-11-02 07:05:07 +08:00
|
|
|
export type StringDecoder = TextDecoder;
|
2018-12-01 03:38:22 +08:00
|
|
|
|
2019-11-02 07:05:07 +08:00
|
|
|
export const supportsBinaryStreams = true;
|
2018-12-01 03:38:22 +08:00
|
|
|
|
2019-11-02 07:05:07 +08:00
|
|
|
export function createStringDecoder(): StringDecoder {
|
|
|
|
|
return new TextDecoder();
|
2018-12-01 03:38:22 +08:00
|
|
|
}
|
|
|
|
|
|
2019-11-02 07:05:07 +08:00
|
|
|
const decoderOptions = {stream: true};
|
2019-10-30 05:45:47 +08:00
|
|
|
|
2019-11-02 07:05:07 +08:00
|
|
|
export function readPartialStringChunk(
|
|
|
|
|
decoder: StringDecoder,
|
|
|
|
|
buffer: Uint8Array,
|
|
|
|
|
): string {
|
|
|
|
|
return decoder.decode(buffer, decoderOptions);
|
2019-10-30 05:45:47 +08:00
|
|
|
}
|
|
|
|
|
|
2019-11-02 07:05:07 +08:00
|
|
|
export function readFinalStringChunk(
|
|
|
|
|
decoder: StringDecoder,
|
|
|
|
|
buffer: Uint8Array,
|
|
|
|
|
): string {
|
|
|
|
|
return decoder.decode(buffer);
|
2019-10-30 05:45:47 +08:00
|
|
|
}
|