Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在node.js缓冲区中搜索字节模式_Node.js - Fatal编程技术网

在node.js缓冲区中搜索字节模式

在node.js缓冲区中搜索字节模式,node.js,Node.js,我有这个node.js缓冲区 var test_buf = "5E4D802158D002001022201022AB778899A1B2C3"; var buffer_hex = new Buffer(test_buf, "hex"); 我想在buffer\u hex中搜索是否存在字节模式77 88 99。从教程中,我找不到合适的缓冲函数来使用。有什么建议吗 您可以使用: 您可以使用buffer\u hex.(或者如果需要偏移量)在缓冲区内查找特定值.includes()接受字符串、数字或其

我有这个node.js缓冲区

var test_buf = "5E4D802158D002001022201022AB778899A1B2C3";
var buffer_hex = new Buffer(test_buf, "hex");
我想在
buffer\u hex
中搜索是否存在字节模式
77 88 99
。从教程中,我找不到合适的缓冲函数来使用。有什么建议吗

您可以使用:


您可以使用
buffer\u hex.
(或者如果需要偏移量)在缓冲区内查找特定值
.includes()
接受字符串、数字或其他缓冲区:

值得注意的是,
.includes()
从节点5.3.0开始就可用

console.log(buffer_hex.includes("778899", 0, "hex")); // boolean
console.log(buffer_hex.indexOf("778899", 0, "hex")); // number

请注意,自节点6起,
new Buffer()
已被弃用。对于那些版本,您应该使用
Buffer.from()

我使用的是节点v4.7,而不是v6。我不确定v4.x是否支持
Buffer.from
。它是?
console.log(buffer_hex.includes("778899", 0, "hex")); // boolean
console.log(buffer_hex.indexOf("778899", 0, "hex")); // number