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.   return decoder.decode(buffer, decoderOptions);
    
  25. }
    
  26. 
    
  27. export function readFinalStringChunk(
    
  28.   decoder: StringDecoder,
    
  29.   buffer: Uint8Array,
    
  30. ): string {
    
  31.   return decoder.decode(buffer);
    
  32. }