0

I wish to add an array to a buffer at a specific offset. This does not work:

let buffer = Buffer.alloc(65);

buffer.writeUInt8(0x91, 0);
buffer.write([127, 0, 0, 1 ], 1);
buffer.write("admin", 5);
buffer.write("admin", 31);

as it gives me the error:

(node:10468) UnhandledPromiseRejectionWarning: TypeError: argument must be a string
robtot
  • 863
  • 1
  • 9
  • 31

1 Answers1

0

Something like this works:

var buf = Buffer.alloc(10);
buf.fill(Buffer.from([ 0x1, 0x2]), 3, 5 );

console.log(buf);

First create a buffer with a length of 10. Fill from position 3 until 5 with array [ 0x1, 0x2 ].

steviethecat
  • 870
  • 9
  • 14