TextDecoderStream: readable property
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2022.
Note: This feature is available in Web Workers.
Thuộc tính chỉ đọc readable của giao diện TextDecoderStream trả về ReadableStream phát ra các chuỗi đã được giải mã.
Giá trị
Một ReadableStream.
Ví dụ
Ví dụ này tạo TextDecoderStream giải mã dữ liệu nhị phân được mã hóa UTF-8. Nó ghi một số dữ liệu nhị phân đã mã hóa vào luồng writable, sau đó đọc văn bản đã giải mã từ luồng readable.
js
const stream = new TextDecoderStream();
// Write data to be decoded
const data = Uint8Array.fromBase64("5L2g5aW95LiW55WM");
const writer = stream.writable.getWriter();
writer.write(data);
writer.close();
// Read decoded data
const reader = stream.readable.getReader();
let done = false;
let output = "";
while (!done) {
const result = await reader.read();
if (result.value) {
output += result.value;
}
done = result.done;
}
console.log(output); // 你好世界
Thông số kỹ thuật
| Specification |
|---|
| Streams> # dom-generictransformstream-readable> |