💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
# 编码方式 ## TextEncoder TextEncoder将代码点流作为输入,并发出字节流。传递给构造函数的编码类型将被忽略,并创建一个UTF-8 TextEncoder。 ### 建设者 [`TextEncoder()`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/TextEncoder)返回一个新构造的函数`TextEncoder`,该函数生成使用UTF-8编码的字节流。`TextEncoder`不带参数且不引发异常。 ### Properties 属性 [`encoding`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encoding)(只读)它[`DOMString`](https://developer.mozilla.org/en-US/docs/Web/API/DOMString)包含编码器的名称,该字符串为描述所用方法的字符串`TextEncoder`(总是`utf-8`)。 ### 方法 [`encode()`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encode)以a[`USVString`](https://developer.mozilla.org/en-US/docs/Web/API/USVString)作为输入,并返回[`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Typed_arrays/Uint8Array)带有UTF-8编码的文本。 ## 文字解码器 所述**TextDecoder**接口表示UTF-8解码器。解码器将字节流作为输入并发出代码点流。 ### 建设者 [`TextDecoder()`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/TextDecoder)返回一个新`TextDecoder`生成的生成代码点流的对象。 ### Properties 属性 * [`encoding`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/encoding)(只读)是一个[`DOMString`](https://developer.mozilla.org/en-US/docs/Web/API/DOMString)带有解码器名称的符号,它描述了`TextDecoder`使用的方法。 * `TextDecoder.fatal`(只读)是一个布尔值,指示错误模式是否致命。 * `TextDecoder.ignoreBOM`(只读)是一个布尔值,指示是否忽略了字节序标记。 ### 方法 [`decode()`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode)返回[`DOMString`](https://developer.mozilla.org/en-US/docs/Web/API/DOMString),其中包含使用`TextDecoder`对象中指定的方法解码的文本。