# 编码方式
## 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`对象中指定的方法解码的文本。
- 关于本翻译文档
- 快速开始
- 模版库
- 讲解
- Workers页面
- 从0开始
- 从已有页面开始
- 从已有Worder开始
- 工具
- Cli工具 wrangler
- 安装
- 指令
- 配置
- 环境
- Webpack
- 密钥
- KV
- 网站
- Playground
- ServerLess插件
- Terraform
- REST API
- Making Requests
- Scripts
- Bindings
- Routes
- Integrations
- 相关
- 工作原理
- 安全
- 使用缓存
- 价格
- Routes
- Limits
- 提示
- 调试技巧
- 调试header
- FetchEvent生命周期
- 请求上下文
- 请求sign
- 参考
- runtime API
- Web Standards
- fetch
- fetchEvent
- Response
- Request
- KV
- Environment Variables
- Streams
- Encoding
- Web Crypto
- Cache API
- HTMLRewriter
- Workers KV
- Use cases
- Namespaces