Lit Aiy Lit Aiy - 5 months ago 67
Node.js Question

Remove element from node.js Buffer

I have a node.js buffer declared in this way;

var buffer_bin;
buffer_bin = new Buffer("ABCDEF", "hex");


Contents of
buffer_bin
is "ab cd ef" in binary bytes.

I want to remove the first byte
ab
from
buffer_bin
such that the contents of
buffer_bin
becomes "cd ef".

Answer

Use the slice method in Buffer object.

 var new_buffer_bin = buffer_bin.slice(1);