MCPcopy Create free account
hub / github.com/p2r3/convert / decodeUsingTextDecoder

Function decodeUsingTextDecoder

src/handlers/textEncoding.ts:83–94  ·  view source on GitHub ↗
(bytes: Uint8Array, label: string)

Source from the content-addressed store, hash-verified

81}
82
83function 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
96const formats: FileFormat[] = [
97 CommonFormats.TEXT.supported("txt", true, true, true), // May or may not have BOM depending on browser

Callers 1

doConvertMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected