티스토리 뷰

728x90
반응형
function arrayBufferToString(buffer: ArrayBuffer): string {
  return String.fromCharCode.apply(null, Array.from(new Uint16Array(buffer)));
}

function stringToArrayBuffer(str: string): ArrayBuffer {
  const stringLength = str.length;
  const buffer = new ArrayBuffer(stringLength * 2);
  const bufferView = new Uint16Array(buffer);
  for (let i = 0; i < stringLength; i++) {
    bufferView[i] = str.charCodeAt(i);
  }
  return buffer;
}

출처 : https://gist.github.com/AndrewLeedham/a7f41ac6bb678f1eb21baf523aa71fd5#file-stringtoarraybuffer-ts-L8

 

TS conversion of https://gist.github.com/skratchdot/e095036fad80597f1c1a

TS conversion of https://gist.github.com/skratchdot/e095036fad80597f1c1a - arrayBufferToString.ts

gist.github.com

 

728x90
반응형

'JavaScript > TypeScript' 카테고리의 다른 글

[TypeScript] JavaScript 프로젝트에 TypeScript 추가  (0) 2022.12.05
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함