Creating Buffers

Buffer objects are actually raw memory allocations. Therefore, you must determine their sizes when you create them. There are three methods for creating Buffer objects using the new keyword:

new Buffer(sizeInBytes)
new Buffer(octetArray)
new Buffer(string, [encoding])

For example, the following lines of code define buffers using a byte size, an octet buffer, and a UTF8 string:

var buf256 = new Buffer(256);
var bufOctets = new Buffer([0x6f, 0x63, 0x74, 0x65, 0x74, 0x73]);
var bufUTF8 = new Buffer("Some UTF8 Text u00b6 u30c6 u20ac", 'utf8'),

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset