Instructions for the buffer.fill method in node.js

  • 2020-05-05 10:52:55
  • OfStack

method description:

Populate buffer with custom data.

syntax:


buffer.fill(value, [offset], [end])

receive parameters:

value                  

offet                   fill the starting position of the data, without specifying the default of 0

end                       the end of the fill data, not specifying the default length of buffer.

Example:


// example 1 , do not specify the starting and ending position of the fill content
var b = new Buffer(50);
b.fill("h");
 
// example 2 Specifies the starting and ending position of the fill content
var b = new Buffer(50);
var len = b.length;
b.fill("h" , len-1 , len);


Related articles: