我正在使用roaring bitmaps来存储ip地址列表。
const RoaringBitmap32 = require('roaring/RoaringBitmap32');
const bitmap2 = new RoaringBitmap32([]);
bitmap2.add("153.171.110.82");
console.log('bitmap2.toArray():', bitmap2.toArray());当我运行上面的程序时,我得到下面的错误-
/Users/rajkumar.natarajan/Documents/Coding/contango/scripts/rr_bitmaps_demo.js:3
bitmap2.add("153.171.110.82");
^
TypeError: RoaringBitmap32::add - 32 bit unsigned integer expected
at Object.<anonymous> (/Users/rajkumar.natarajan/Documents/Coding/contango/scripts/rr_bitmaps_demo.js:3:9)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3有什么办法可以解决这个错误吗?
发布于 2019-07-25 19:27:09
您首先需要按照错误提示将您的IP转换为32位整数。IPv4由4个块组成,每个块是8位,所以它总共是32位。
你可以写你自己的转换函数,我相信这应该不会太难,但如果这对你来说是有问题的,那么应该有一些npm包可以使用。例如,我找到了this one
https://stackoverflow.com/questions/57193344
复制相似问题