Converting between strings and ArrayBuffers

后端 未结 24 1218
慢半拍i
慢半拍i 2020-11-22 04:50

Is there a commonly accepted technique for efficiently converting JavaScript strings to ArrayBuffers and vice-versa? Specifically, I\'d like to be able to write the contents

24条回答
  •  轮回少年
    2020-11-22 05:26

    Let's say you have an arrayBuffer binaryStr:

    let text = String.fromCharCode.apply(null, new Uint8Array(binaryStr));
    

    and then you assign the text to the state.

提交回复
热议问题