@node-rs/crc32
Advanced tools
+21
| MIT License | ||
| Copyright (c) 2020-present LongYinan | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
+13
-12
@@ -1,12 +0,13 @@ | ||
| /** | ||
| * @param {string | Buffer} input string or buffer to calculate | ||
| * @param {number} crc u32 number, default 0 | ||
| * @returns {number} u32 number | ||
| */ | ||
| export function crc32(input: Buffer | string, crc?: number): number | ||
| /** | ||
| * @param {string | Buffer} input string or buffer to calculate | ||
| * @param {number} crc u32 number, default 0 | ||
| * @returns {number} u32 number | ||
| */ | ||
| export function crc32c(input: Buffer | string, crc?: number): number | ||
| /* tslint:disable */ | ||
| /* eslint-disable */ | ||
| /* auto-generated by NAPI-RS */ | ||
| export class ExternalObject<T> { | ||
| readonly '': { | ||
| readonly '': unique symbol | ||
| [K: symbol]: T | ||
| } | ||
| } | ||
| export function crc32c(input: string | Buffer, initialState?: number | undefined | null): number | ||
| export function crc32(inputData: string | Buffer, initialState?: number | undefined | null): number |
+195
-11
@@ -1,14 +0,198 @@ | ||
| const { loadBinding } = require('@node-rs/helper') | ||
| const { existsSync, readFileSync } = require('fs') | ||
| const { join } = require('path') | ||
| const binding = loadBinding(__dirname, 'crc32', '@node-rs/crc32') | ||
| const { platform, arch } = process | ||
| module.exports = { | ||
| crc32: function crc32(input, crc = 0) { | ||
| const _input = Buffer.isBuffer(input) ? input : Buffer.from(input) | ||
| return binding.crc32(_input, crc) | ||
| }, | ||
| crc32c: function crc32c(input, crc = 0) { | ||
| const _input = Buffer.isBuffer(input) ? input : Buffer.from(input) | ||
| return binding.crc32c(_input, crc) | ||
| }, | ||
| let nativeBinding = null | ||
| let localFileExisted = false | ||
| let isMusl = false | ||
| let loadError = null | ||
| switch (platform) { | ||
| case 'android': | ||
| if (arch !== 'arm64') { | ||
| throw new Error(`Unsupported architecture on Android ${arch}`) | ||
| } | ||
| localFileExisted = existsSync(join(__dirname, 'crc32.android-arm64.node')) | ||
| try { | ||
| if (localFileExisted) { | ||
| nativeBinding = require('./crc32.android-arm64.node') | ||
| } else { | ||
| nativeBinding = require('@node-rs/crc32-android-arm64') | ||
| } | ||
| } catch (e) { | ||
| loadError = e | ||
| } | ||
| break | ||
| case 'win32': | ||
| switch (arch) { | ||
| case 'x64': | ||
| localFileExisted = existsSync(join(__dirname, 'crc32.win32-x64-msvc.node')) | ||
| try { | ||
| if (localFileExisted) { | ||
| nativeBinding = require('./crc32.win32-x64-msvc.node') | ||
| } else { | ||
| nativeBinding = require('@node-rs/crc32-win32-x64-msvc') | ||
| } | ||
| } catch (e) { | ||
| loadError = e | ||
| } | ||
| break | ||
| case 'ia32': | ||
| localFileExisted = existsSync(join(__dirname, 'crc32.win32-ia32-msvc.node')) | ||
| try { | ||
| if (localFileExisted) { | ||
| nativeBinding = require('./crc32.win32-ia32-msvc.node') | ||
| } else { | ||
| nativeBinding = require('@node-rs/crc32-win32-ia32-msvc') | ||
| } | ||
| } catch (e) { | ||
| loadError = e | ||
| } | ||
| break | ||
| case 'arm64': | ||
| localFileExisted = existsSync(join(__dirname, 'crc32.win32-arm64-msvc.node')) | ||
| try { | ||
| if (localFileExisted) { | ||
| nativeBinding = require('./crc32.win32-arm64-msvc.node') | ||
| } else { | ||
| nativeBinding = require('@node-rs/crc32-win32-arm64-msvc') | ||
| } | ||
| } catch (e) { | ||
| loadError = e | ||
| } | ||
| break | ||
| default: | ||
| throw new Error(`Unsupported architecture on Windows: ${arch}`) | ||
| } | ||
| break | ||
| case 'darwin': | ||
| switch (arch) { | ||
| case 'x64': | ||
| localFileExisted = existsSync(join(__dirname, 'crc32.darwin-x64.node')) | ||
| try { | ||
| if (localFileExisted) { | ||
| nativeBinding = require('./crc32.darwin-x64.node') | ||
| } else { | ||
| nativeBinding = require('@node-rs/crc32-darwin-x64') | ||
| } | ||
| } catch (e) { | ||
| loadError = e | ||
| } | ||
| break | ||
| case 'arm64': | ||
| localFileExisted = existsSync(join(__dirname, 'crc32.darwin-arm64.node')) | ||
| try { | ||
| if (localFileExisted) { | ||
| nativeBinding = require('./crc32.darwin-arm64.node') | ||
| } else { | ||
| nativeBinding = require('@node-rs/crc32-darwin-arm64') | ||
| } | ||
| } catch (e) { | ||
| loadError = e | ||
| } | ||
| break | ||
| default: | ||
| throw new Error(`Unsupported architecture on macOS: ${arch}`) | ||
| } | ||
| break | ||
| case 'freebsd': | ||
| if (arch !== 'x64') { | ||
| throw new Error(`Unsupported architecture on FreeBSD: ${arch}`) | ||
| } | ||
| localFileExisted = existsSync(join(__dirname, 'crc32.freebsd-x64.node')) | ||
| try { | ||
| if (localFileExisted) { | ||
| nativeBinding = require('./crc32.freebsd-x64.node') | ||
| } else { | ||
| nativeBinding = require('@node-rs/crc32-freebsd-x64') | ||
| } | ||
| } catch (e) { | ||
| loadError = e | ||
| } | ||
| break | ||
| case 'linux': | ||
| switch (arch) { | ||
| case 'x64': | ||
| isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl') | ||
| if (isMusl) { | ||
| localFileExisted = existsSync(join(__dirname, 'crc32.linux-x64-musl.node')) | ||
| try { | ||
| if (localFileExisted) { | ||
| nativeBinding = require('./crc32.linux-x64-musl.node') | ||
| } else { | ||
| nativeBinding = require('@node-rs/crc32-linux-x64-musl') | ||
| } | ||
| } catch (e) { | ||
| loadError = e | ||
| } | ||
| } else { | ||
| localFileExisted = existsSync(join(__dirname, 'crc32.linux-x64-gnu.node')) | ||
| try { | ||
| if (localFileExisted) { | ||
| nativeBinding = require('./crc32.linux-x64-gnu.node') | ||
| } else { | ||
| nativeBinding = require('@node-rs/crc32-linux-x64-gnu') | ||
| } | ||
| } catch (e) { | ||
| loadError = e | ||
| } | ||
| } | ||
| break | ||
| case 'arm64': | ||
| isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl') | ||
| if (isMusl) { | ||
| localFileExisted = existsSync(join(__dirname, 'crc32.linux-arm64-musl.node')) | ||
| try { | ||
| if (localFileExisted) { | ||
| nativeBinding = require('./crc32.linux-arm64-musl.node') | ||
| } else { | ||
| nativeBinding = require('@node-rs/crc32-linux-arm64-musl') | ||
| } | ||
| } catch (e) { | ||
| loadError = e | ||
| } | ||
| } else { | ||
| localFileExisted = existsSync(join(__dirname, 'crc32.linux-arm64-gnu.node')) | ||
| try { | ||
| if (localFileExisted) { | ||
| nativeBinding = require('./crc32.linux-arm64-gnu.node') | ||
| } else { | ||
| nativeBinding = require('@node-rs/crc32-linux-arm64-gnu') | ||
| } | ||
| } catch (e) { | ||
| loadError = e | ||
| } | ||
| } | ||
| break | ||
| case 'arm': | ||
| localFileExisted = existsSync(join(__dirname, 'crc32.linux-arm-gnueabihf.node')) | ||
| try { | ||
| if (localFileExisted) { | ||
| nativeBinding = require('./crc32.linux-arm-gnueabihf.node') | ||
| } else { | ||
| nativeBinding = require('@node-rs/crc32-linux-arm-gnueabihf') | ||
| } | ||
| } catch (e) { | ||
| loadError = e | ||
| } | ||
| break | ||
| default: | ||
| throw new Error(`Unsupported architecture on Linux: ${arch}`) | ||
| } | ||
| break | ||
| default: | ||
| throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`) | ||
| } | ||
| if (!nativeBinding) { | ||
| if (loadError) { | ||
| throw loadError | ||
| } | ||
| throw new Error(`Failed to load native binding`) | ||
| } | ||
| const { crc32c, crc32 } = nativeBinding | ||
| module.exports.crc32c = crc32c | ||
| module.exports.crc32 = crc32 |
+20
-19
| { | ||
| "name": "@node-rs/crc32", | ||
| "version": "1.2.2", | ||
| "version": "1.3.0", | ||
| "description": "SIMD crc32", | ||
@@ -34,2 +34,3 @@ "keywords": [ | ||
| "aarch64-linux-android", | ||
| "armv7-linux-androideabi", | ||
| "x86_64-unknown-freebsd", | ||
@@ -55,4 +56,5 @@ "aarch64-unknown-linux-musl", | ||
| "bench": "cross-env NODE_ENV=production node benchmark/crc32.js", | ||
| "build": "napi build --platform --release", | ||
| "build:debug": "napi build --platform", | ||
| "build": "napi build --platform --release --pipe \"prettier -w\"", | ||
| "build:debug": "napi build --platform --pipe \"prettier -w\"", | ||
| "prepublishOnly": "napi prepublish", | ||
| "version": "napi version" | ||
@@ -63,8 +65,5 @@ }, | ||
| }, | ||
| "dependencies": { | ||
| "@node-rs/helper": "^1.2.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/crc": "^3.4.0", | ||
| "crc": "^3.8.0", | ||
| "crc": "^4.0.0", | ||
| "sse4_crc32": "^6.0.1" | ||
@@ -76,16 +75,18 @@ }, | ||
| }, | ||
| "gitHead": "baa8a4702e3e71b80f2eeebbf3cb6e384a94eb74", | ||
| "optionalDependencies": { | ||
| "@node-rs/crc32-win32-x64-msvc": "1.2.2", | ||
| "@node-rs/crc32-darwin-x64": "1.2.2", | ||
| "@node-rs/crc32-linux-x64-gnu": "1.2.2", | ||
| "@node-rs/crc32-win32-ia32-msvc": "1.2.2", | ||
| "@node-rs/crc32-linux-arm-gnueabihf": "1.2.2", | ||
| "@node-rs/crc32-linux-x64-musl": "1.2.2", | ||
| "@node-rs/crc32-linux-arm64-gnu": "1.2.2", | ||
| "@node-rs/crc32-darwin-arm64": "1.2.2", | ||
| "@node-rs/crc32-android-arm64": "1.2.2", | ||
| "@node-rs/crc32-freebsd-x64": "1.2.2", | ||
| "@node-rs/crc32-linux-arm64-musl": "1.2.2", | ||
| "@node-rs/crc32-win32-arm64-msvc": "1.2.2" | ||
| "@node-rs/crc32-win32-x64-msvc": "1.3.0", | ||
| "@node-rs/crc32-darwin-x64": "1.3.0", | ||
| "@node-rs/crc32-linux-x64-gnu": "1.3.0", | ||
| "@node-rs/crc32-win32-ia32-msvc": "1.3.0", | ||
| "@node-rs/crc32-linux-arm-gnueabihf": "1.3.0", | ||
| "@node-rs/crc32-linux-x64-musl": "1.3.0", | ||
| "@node-rs/crc32-linux-arm64-gnu": "1.3.0", | ||
| "@node-rs/crc32-darwin-arm64": "1.3.0", | ||
| "@node-rs/crc32-android-arm64": "1.3.0", | ||
| "@node-rs/crc32-android-arm-eabi": "1.3.0", | ||
| "@node-rs/crc32-freebsd-x64": "1.3.0", | ||
| "@node-rs/crc32-linux-arm64-musl": "1.3.0", | ||
| "@node-rs/crc32-win32-arm64-msvc": "1.3.0" | ||
| } | ||
| } |
+1
-0
@@ -58,2 +58,3 @@ # `@node-rs/crc32` | ||
| | Android arm64 | ✓ | ✓ | ✓ | | ||
| | Android armv7 | ✓ | ✓ | ✓ | | ||
| | FreeBSD x64 | ✓ | ✓ | ✓ | | ||
@@ -60,0 +61,0 @@ |
-47
| # Change Log | ||
| All notable changes to this project will be documented in this file. | ||
| See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
| ## [1.2.2](https://github.com/napi-rs/node-rs/compare/@node-rs/crc32@1.2.1...@node-rs/crc32@1.2.2) (2021-10-22) | ||
| **Note:** Version bump only for package @node-rs/crc32 | ||
| ## [1.2.1](https://github.com/napi-rs/node-rs/compare/@node-rs/crc32@1.2.0...@node-rs/crc32@1.2.1) (2021-07-22) | ||
| **Note:** Version bump only for package @node-rs/crc32 | ||
| # [1.2.0](https://github.com/napi-rs/node-rs/compare/@node-rs/crc32@1.1.2...@node-rs/crc32@1.2.0) (2021-07-18) | ||
| ### Features | ||
| - Support ARM v8 crc32c instructions ([#370](https://github.com/napi-rs/node-rs/issues/370)) | ||
| - Switch to nightly toolchain, strip symbols ([#463](https://github.com/napi-rs/node-rs/pull/463)) | ||
| ## [1.1.2](https://github.com/napi-rs/node-rs/compare/@node-rs/crc32@1.1.1...@node-rs/crc32@1.1.2) (2021-06-08) | ||
| **Note:** Version bump only for package @node-rs/crc32 | ||
| ## [1.1.1](https://github.com/napi-rs/node-rs/compare/@node-rs/crc32@1.1.0...@node-rs/crc32@1.1.1) (2021-06-01) | ||
| **Note:** Version bump only for package @node-rs/crc32 | ||
| # [1.1.0](https://github.com/napi-rs/node-rs/compare/@node-rs/crc32@1.0.0...@node-rs/crc32@1.1.0) (2021-02-01) | ||
| ### Features | ||
| - support win32-i686 platform ([c0f2f62](https://github.com/napi-rs/node-rs/commit/c0f2f62adc1fae15263086781e34d78d8eeeaecc)) | ||
| ## [0.5.1](https://github.com/napi-rs/node-rs/compare/@node-rs/crc32@0.5.0...@node-rs/crc32@0.5.1) (2020-09-08) | ||
| ### Performance Improvements | ||
| - **crc32:** avoid useless typeof ([345fc04](https://github.com/napi-rs/node-rs/commit/345fc04f8b9e4d56b73d51ab4b3254f581fc86cb)) | ||
| # [0.5.0](https://github.com/napi-rs/node-rs/compare/@node-rs/crc32@0.4.1...@node-rs/crc32@0.5.0) (2020-09-04) | ||
| **Note:** Version bump only for package @node-rs/crc32 | ||
| ## [0.3.3](https://github.com/napi-rs/node-rs/compare/@node-rs/crc32@0.3.2...@node-rs/crc32@0.3.3) (2020-08-18) | ||
| **Note:** Version bump only for package @node-rs/crc32 |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
13384
54.91%203
745.83%80
1.27%1
Infinity%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed