You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Create an empty buffer of size 10. // A buffer that only can accommodate 10 bytes.const buf1 = Buffer.alloc(10);// Create a buffer with contentconst buf2 = Buffer.from("hello buffer");
interacting with buffer
// Examine the structure of a bufferbuf1.toJSON()// { type: 'Buffer', data: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] }// an empty bufferbuf2.toJSON()// { type: 'Buffer',data: [ 104, 101, 108, 108, 111, 32, 98, 117, 102, 102, 101, 114 ] }// the toJSON() method presents the data as the Unicode Code Points of the characters// Examine the size of a bufferbuf1.length // 10buf2.length // 12. Auto-assigned based on the initial content when created.// Write to a bufferbuf1.write("Buffer really rocks!")
// Decode a bufferbuf1.toString() // 'Buffer rea'//oops, because buf1 is created to contain only 10 bytes, it couldn't accommodate the rest of the characters// Compare two buffers