A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/zh-CN/docs/Web/API/TextDecoderStream/TextDecoderStream below:

TextDecoderStream() - Web API | MDN

TextDecoderStream()

Baseline Widely available

TextDecoderStream() 构造函数创建一个新的 TextDecoderStream 对象,该对象用于将二进制编码的文本流转换为字符串。

语法
new TextDecoderStream(label)
new TextDecoderStream(label, options)
参数
label

默认为 utf-8 的字符串。可以是任意有效的编码。

options 可选

一个具有属性的 TextDecoderOptions 对象:

fatal

一个布尔值,表示错误的模式。如果是 true,则在 decoder 遇到错误时抛出一个 DOMException。默认值是 false。

示例

以下示例演示如何从一个 fetch() 中获取并解码二进制数据。如果没有传递任何 label,数据的解码类型为 UTF-8。

const response = await fetch("https://example.com");
const stream = response.body.pipeThrough(new TextDecoderStream());
规范 浏览器兼容性

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4