buf.equals(otherBuffer)
版本历史
| 版本 | 变更 |
|---|---|
| v8.0.0 | 参数现在可以是 |
| v0.11.13 | 新增于: v0.11.13 |
-
otherBuffer<Buffer> | <Uint8Array> 用于比较buf的Buffer或Uint8Array。\
otherBuffer<Buffer> | <Uint8Array> ABufferorUint8Arraywith which to comparebuf. -
返回:<boolean>
\Returns: <boolean>
如果 buf 和 otherBuffer 具有完全相同的字节,则返回 true,否则返回 false。相当于 buf.compare(otherBuffer) === 0。
\Returns true if both buf and otherBuffer have exactly the same bytes,
false otherwise. Equivalent to
buf.compare(otherBuffer) === 0.
import { Buffer } from 'node:buffer'; const buf1 = Buffer.from('ABC'); const buf2 = Buffer.from('414243', 'hex'); const buf3 = Buffer.from('ABCD'); console.log(buf1.equals(buf2)); // Prints: true console.log(buf1.equals(buf3)); // Prints: falseconst { Buffer } = require('node:buffer'); const buf1 = Buffer.from('ABC'); const buf2 = Buffer.from('414243', 'hex'); const buf3 = Buffer.from('ABCD'); console.log(buf1.equals(buf2)); // Prints: true console.log(buf1.equals(buf3)); // Prints: false