UNPKG

617 BPlain TextView Raw
1/**
2 * @prettier
3 */
4import { StringDecoder } from 'string_decoder';
5
6/**
7 * Custom utf8 TextDecoder that uses StringDecoder under the hood.
8 * This should only be used with utf8 and does NOT support TextDecoder options, like streaming.
9 */
10export class StringTextDecoder extends TextDecoder {
11 public decode(input?: BufferSource, options?: TextDecodeOptions): string {
12 // Note: streaming is not necessary for deserializing EOS transactions.
13 const decoder = new StringDecoder('utf8');
14
15 if (input) {
16 const decoded = decoder.end(Buffer.from(input));
17 return decoded;
18 }
19
20 return '';
21 }
22}