From 0e11a9732efc76754b485c5988e897e2494c1307 Mon Sep 17 00:00:00 2001 From: Ryan Lester Date: Wed, 5 May 2021 00:40:04 -0400 Subject: [PATCH] fix and optimization for non-x86 architectures https://github.com/ashi009/node-fast-crc32c/issues/21 --- impls/rs_crc32c.js | 5 +++++ loader.js | 5 ++++- package.json | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 impls/rs_crc32c.js diff --git a/impls/rs_crc32c.js b/impls/rs_crc32c.js new file mode 100644 index 0000000..72750ae --- /dev/null +++ b/impls/rs_crc32c.js @@ -0,0 +1,5 @@ +const {crc32c} = require('@node-rs/crc32'); + +module.exports = { + calculate: crc32c, +}; diff --git a/loader.js b/loader.js index a983814..df56b5d 100644 --- a/loader.js +++ b/loader.js @@ -1,6 +1,9 @@ module.exports = (function() { + const os = require('os'); + const isX86 = new Set(['ia32', 'x32', 'x64']).has(os.arch()); const impls = [ - './impls/sse4_crc32c', + ...(isX86 ? ['./impls/sse4_crc32c'] : []), + './impls/rs_crc32c', './impls/js_crc32c', ]; for (const impl of impls) { diff --git a/package.json b/package.json index 738bde8..47b0bba 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "main": "./loader", "optionalDependencies": { + "@node-rs/crc32": "^1.1.0", "sse4_crc32": "^6.0.1" }, "scripts": {