You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将Uint8数组流转为单个字符串:问题及解决方法

将Uint8数组流转换为单个字符串的问题

我有一系列Uint8数组流,需要将其转换为单个字符串。尝试使用TextDecoderStream进行解码,虽能完成解码,但始终返回多个字符串而非单个。我的代码如下:

const textDecoder = new TextDecoderStream();
port.readable.pipeTo(textDecoder.writable);
const reader = textDecoder.readable.getReader();
while (true) {
  const { value, done } = await reader.read();
  if (done) {
    reader.releaseLock();
    break;
  }
  console.log(value);
}

请问有什么解决建议?


补充说明

最终我通过for循环和join函数得到了最终字符串,实现代码如下:

for (let i = 0; i < arrLength; i++) {
  const { value } = await reader.read();
  if (value) {
   arr.push(value);
  }
}
const rfidString = arr.join("");

内容的提问来源于stack exchange,提问作者Adam Šulc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 04:40:23