(text: string, encoding: string)
| 45 | } |
| 46 | |
| 47 | encode(text: string, encoding: string): Uint8Array { |
| 48 | if (encoding !== 'utf-8' && encoding !== 'utf8') { |
| 49 | throw new Error( |
| 50 | `Browser's encoder only supports utf-8, but got ${encoding}`); |
| 51 | } |
| 52 | if (this.textEncoder == null) { |
| 53 | this.textEncoder = new TextEncoder(); |
| 54 | } |
| 55 | return this.textEncoder.encode(text); |
| 56 | } |
| 57 | decode(bytes: Uint8Array, encoding: string): string { |
| 58 | return new TextDecoder(encoding).decode(bytes); |
| 59 | } |