2020/12/30 - [기타] - 아스키코드표 (ASCII)
↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
Buffer사용에 필요한 16진수 코드표 보기
Buffer.alloc()
size <integer>
fill <string> | <Buffer> | <Uint8Array> | <integer> (Default: 0)
encoding <string>
예제)
Buffer.alloc(10);
Buffer.alloc(10,"A");
Buffer.alloc(10,"ABCD");
Buffer.from()
1.
arrayBuffer <ArrayBuffer> | <SharedArrayBuffer>
byteOffset <integer>
length <integer>
예제)
Buffer.from([0x41,0x42,0x43]);
Buffer.from("ABC DEF");
2.
string <string>
encoding <string> (Default: 'utf8')
예제)
Buffer.from("4142434445",'hex');
참고)
Buffer.from(Array.from({length:5},(v,i)=>i));
이런식으로 쓰면 Buffer가 0,1,2,3,4 로 쓰인다.
Buffer.includes()
예제)
let temp = Buffer.from("Hello World");
let test = temp.includes("Hello");
Buffer.readInt16BE()
외에 readBigInt64BE, readBigUInt64BE, readDoubleBE, readInt8, ReadUInt16BE 등이 있음.
BE = Big Endian
예제)
let temp = Buffer.from([0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04]);
let test1 = temp.readInt16BE(0);
let test2 = temp.readInt16BE(2);
let test3 = temp.readInt16BE(4);
let test4 = temp.readInt16BE(6);
Buffer.readInt16LE()
외에 readBigInt64LE, readBigUInt64LE, readDoubleLE, readInt8, ReadUInt16LE 등이 있음.
LE = Little Endian
예제)
let temp = Buffer.from([0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04]);
let test1 = temp.readInt16LE(0); // 0x0100
let test2 = temp.readInt16LE(2); // 0x0200
let test3 = temp.readInt16LE(4); // 0x0300
let test4 = temp.readInt16LE(6); // 0x0400
let test = temp.readInt16LE(7); //error BE도 offset 에러는 같음.
Buffer.writeInt16LE()
read와 마찬가지로 writeUint64LE 등이 있음.
LE = Little Endian
let test = Buffer.alloc(10,0);
test.writeInt16LE(0x0001,0);
test.writeInt16LE(0x0002,2);
test.writeInt16LE(0x0003,4);
test.writeInt16LE(0x0004,6);
test.writeInt16LE(0x0005,8);
Buffer.writeInt16BE()
let test = Buffer.alloc(10,0);
test.writeInt16BE(0x0001,0);
test.writeInt16BE(0x0002,2);
test.writeInt16BE(0x0003,4);
test.writeInt16BE(0x0004,6);
test.writeInt16BE(0x0005,8);
Buffer.concat()
list <Buffer[]> | <Uint8Array[]>
totalLength <integer>
예제)
let temp1 = Buffer.from([0x01,0x02,0x03]);
let temp2 = Buffer.from([0x04,0x05,0x06]);
let temp3 = Buffer.from([0x07,0x08,0x09]);
let test = Buffer.concat([temp1,temp2,temp3]);
let temp1 = Buffer.from([0x01,0x02,0x03]);
let temp2 = Buffer.from([0x04,0x05,0x06]);
let temp3 = Buffer.from([0x07,0x08,0x09]);
let test = Buffer.concat([temp1,temp2,temp3],5);
'프로그래밍 > NodeJS' 카테고리의 다른 글
[NodeJS] 프롬프트 기반 입출력 처리 (0) | 2024.09.23 |
---|---|
[NodeJS] Sematic URL여러개를 하나의 변수로 받아오기 (0) | 2023.03.02 |
npm nodemodules import하기 (0) | 2023.01.30 |
[JS] webserver 최대 크기 문제 해결(feat. dropzone) (2) | 2022.12.18 |
nodejs&nginx 연동하기 (0) | 2022.12.04 |
댓글