天天看點

Node buffer子產品緩沖區

//1:位元組 byte

//1024b = 1kb [千位元組]

//1024kb = 1mb [兆位元組]

//1024mb = 1gb [吉位元組]

//1024gb = 1tb [梯]

//1024tb = 1pb

//1:建立大小為1024位元組緩沖區

var buf1 = Buffer.alloc(1024);

console.log(buf1);

console.log(buf1.length);

//2:建立3KB大小緩沖區

var buf2 = Buffer.alloc(1024*3);

console.log(buf2);

//3:建立一個數組初始化緩沖區

var buf3 = Buffer.from([1,2,3,4,5]);

console.log(buf3);

//4:建立一個字元串緩沖區

var buf4 = Buffer.from("一二三");

console.log(buf4);

console.log(buf4.toString());

繼續閱讀