| 81 | } |
| 82 | |
| 83 | function decodeUsingTextDecoder(bytes: Uint8Array, label: string) { |
| 84 | try { |
| 85 | // TextDecoder labels are typically 'utf-8', 'utf-16le', 'utf-16be', etc. |
| 86 | // Not all environments support utf-16 labels, so fall back if needed. |
| 87 | const dec = new TextDecoder(label); |
| 88 | return dec.decode(bytes); |
| 89 | } catch { |
| 90 | // fallback |
| 91 | const dec = new TextDecoder("utf-8"); |
| 92 | return dec.decode(bytes); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | const formats: FileFormat[] = [ |
| 97 | CommonFormats.TEXT.supported("txt", true, true, true), // May or may not have BOM depending on browser |