1 | const { loadBinding } = require('@node-rs/helper')
|
2 |
|
3 | const {
|
4 | xxh32: _xxh32,
|
5 | xxh64: _xxh64,
|
6 | Xxh32: _Xxh32,
|
7 | Xxh64: _Xxh64,
|
8 | xxh3,
|
9 | } = loadBinding(__dirname, 'xxhash', '@node-rs/xxhash')
|
10 |
|
11 | class Xxh3 {
|
12 | update(data) {
|
13 | return xxh3.update.call(this, Buffer.from(data))
|
14 | }
|
15 | }
|
16 |
|
17 | Xxh3.withSecret = function withSecret(secret) {
|
18 | const instance = new Xxh3()
|
19 | xxh3.createXxh3WithSecret(instance, Buffer.from(secret))
|
20 | return instance
|
21 | }
|
22 |
|
23 | Xxh3.withSeed = function withSeed(seed = BigInt(0)) {
|
24 | const instance = new Xxh3()
|
25 | xxh3.createXxh3WithSeed(instance, seed)
|
26 | return instance
|
27 | }
|
28 |
|
29 | Xxh3.prototype.digest = xxh3.digest
|
30 | Xxh3.prototype.reset = xxh3.reset
|
31 |
|
32 | module.exports = {
|
33 | xxh32: function xxh32(input, seed) {
|
34 | return _xxh32(Buffer.isBuffer(input) ? input : Buffer.from(input), seed == null ? 0 : seed)
|
35 | },
|
36 | xxh64: function xxh64(input, seed) {
|
37 | return _xxh64(Buffer.isBuffer(input) ? input : Buffer.from(input), seed == null ? BigInt(0) : seed)
|
38 | },
|
39 | Xxh32: class Xxh32 extends _Xxh32 {
|
40 | update(input) {
|
41 | return super.update(Buffer.isBuffer(input) ? input : Buffer.from(input))
|
42 | }
|
43 | },
|
44 | Xxh64: class Xxh64 extends _Xxh64 {
|
45 | update(input) {
|
46 | return super.update(Buffer.isBuffer(input) ? input : Buffer.from(input))
|
47 | }
|
48 | },
|
49 | xxh3: {
|
50 | xxh64: function xxh64(input, seed) {
|
51 | return xxh3.xxh64(Buffer.isBuffer(input) ? input : Buffer.from(input), seed == null ? BigInt(0) : seed)
|
52 | },
|
53 | xxh64WithSecret(input, secret) {
|
54 | return xxh3.xxh64WithSecret(Buffer.isBuffer(input) ? input : Buffer.from(input), Buffer.from(secret))
|
55 | },
|
56 | xxh128: function xxh128(input, seed) {
|
57 | return xxh3.xxh128(Buffer.isBuffer(input) ? input : Buffer.from(input), seed == null ? BigInt(0) : seed)
|
58 | },
|
59 | xxh128WithSecret(input, secret) {
|
60 | return xxh3.xxh128WithSecret(Buffer.isBuffer(input) ? input : Buffer.from(input), Buffer.from(secret))
|
61 | },
|
62 | Xxh3,
|
63 | },
|
64 | }
|