buf.compare(otherBuffer)
- otherBuffer {Buffer}
- 返回:{Number}
- 如果 otherBuffer 和 buf 相同,则返回 0
- 如果 otherBuffer 排在 buf 前面,则返回 1
- 如果 otherBuffer 排在 buf 后面,则返回 -1
console.log(buf1.compare(buf1));
// Prints: 0
console.log(buf1.compare(buf2));
// Prints: -1
console.log(buf1.compare(buf3));
// Prints: 1
console.log(buf2.compare(buf1));
// Prints: 1
console.log(buf2.compare(buf3));
// Prints: 1
[buf1, buf2, buf3].sort(Buffer.compare);
// produces sort order [buf1, buf3, buf2]