• buf1 {Buffer|Uint8Array}
    • buf2 {Buffer|Uint8Array}
    • 返回: {integer} -101,取决于比较的结果。 有关详细信息,参见 [buf.compare()]。

    比较 buf1buf2,主要用于 Buffer 实例数组的排序。 相当于调用 [buf1.compare(buf2)][buf.compare()]。

    1. const buf1 = Buffer.from('1234');
    2. const buf2 = Buffer.from('0123');
    3. const arr = [buf1, buf2];
    4. console.log(arr.sort(Buffer.compare));
    5. // 打印: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ]
    6. // (结果相当于: [buf2, buf1])