I have following stream of Uint8 arrays that I need to convert to singular string.
So far I have tried to decode the array using TextDecoderStream
, which it does, but it always returns multiple strings instead of one.
This is my code:
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);
}
Any suggestions how to solve this?
Thank you in advance
EDIT:
Eventully I managed to get the final string using for
loop and join
function:
for (let i = 0; i < arrLength; i++) {
const { value } = await reader.read();
if (value) {
arr.push(value);
}
}
const rfidString = arr.join("");