buffer.swap16()

buf.swap16()

Interprets the Buffer as an array of unsigned 16-bit integers and swaps the byte-order in-place. Throws a RangeError if the Buffer length is not a multiple of 16 bits. The method returns a reference to the Buffer, so calls can be chained.

const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
console.log(buf);
  // Prints Buffer(0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8)
buf.swap16();
console.log(buf);
  // Prints Buffer(0x2, 0x1, 0x4, 0x3, 0x6, 0x5, 0x8, 0x7)
doc_Nodejs
2016-04-30 04:37:43
Comments
Leave a Comment

Please login to continue.