diff --git a/__test__/__fixtures__/weird-diff-2.png b/__test__/__fixtures__/weird-diff-2.png new file mode 100644 index 0000000..b06ce68 Binary files /dev/null and b/__test__/__fixtures__/weird-diff-2.png differ diff --git a/__test__/__fixtures__/weird-diff.png b/__test__/__fixtures__/weird-diff.png new file mode 100644 index 0000000..7d07ffb Binary files /dev/null and b/__test__/__fixtures__/weird-diff.png differ diff --git a/__test__/index.spec.ts b/__test__/index.spec.ts index 09b26cd..8786e06 100644 --- a/__test__/index.spec.ts +++ b/__test__/index.spec.ts @@ -31,6 +31,11 @@ describe('diff fingerprint', () => { const fA3 = await generateFingerprintFromFilename('diff-A3.png') const fB1 = await generateFingerprintFromFilename('diff-B1.png') const fLong = await generateFingerprintFromFilename('long-diff.png') + const weirdDiff = await generateFingerprintFromFilename('weird-diff.png') + const weirdDiff2 = await generateFingerprintFromFilename('weird-diff-2.png') + + expect(weirdDiff).toBe('v1:g16:d1:t0.002,0.02,0.08:badfb9bd5eea0beb') + expect(weirdDiff2).toBe('v1:g16:d1:t0.002,0.02,0.08:ccb73aa8a5d0317b') expect(fA1).toBe('v1:g16:d1:t0.002,0.02,0.08:202566ca9533046b') expect(fA1).toBe(fA2) diff --git a/index.js b/index.js index bbde722..7a73352 100644 --- a/index.js +++ b/index.js @@ -77,8 +77,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-android-arm64') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-android-arm64/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -93,8 +93,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-android-arm-eabi') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-android-arm-eabi/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -114,8 +114,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-win32-x64-gnu') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-win32-x64-gnu/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -130,8 +130,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-win32-x64-msvc') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-win32-x64-msvc/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -147,8 +147,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-win32-ia32-msvc') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-win32-ia32-msvc/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -163,8 +163,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-win32-arm64-msvc') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-win32-arm64-msvc/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -182,8 +182,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-darwin-universal') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-darwin-universal/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -198,8 +198,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-darwin-x64') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-darwin-x64/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -214,8 +214,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-darwin-arm64') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-darwin-arm64/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -234,8 +234,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-freebsd-x64') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-freebsd-x64/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -250,8 +250,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-freebsd-arm64') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-freebsd-arm64/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -271,8 +271,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-linux-x64-musl') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-linux-x64-musl/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -287,8 +287,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-linux-x64-gnu') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-linux-x64-gnu/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -305,8 +305,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-linux-arm64-musl') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-linux-arm64-musl/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -321,8 +321,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-linux-arm64-gnu') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-linux-arm64-gnu/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -339,8 +339,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-linux-arm-musleabihf') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-linux-arm-musleabihf/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -355,8 +355,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-linux-arm-gnueabihf') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-linux-arm-gnueabihf/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -373,8 +373,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-linux-loong64-musl') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-linux-loong64-musl/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -389,8 +389,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-linux-loong64-gnu') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-linux-loong64-gnu/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -407,8 +407,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-linux-riscv64-musl') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-linux-riscv64-musl/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -423,8 +423,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-linux-riscv64-gnu') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-linux-riscv64-gnu/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -440,8 +440,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-linux-ppc64-gnu') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-linux-ppc64-gnu/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -456,8 +456,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-linux-s390x-gnu') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-linux-s390x-gnu/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -476,8 +476,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-openharmony-arm64') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-openharmony-arm64/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -492,8 +492,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-openharmony-x64') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-openharmony-x64/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -508,8 +508,8 @@ function requireNative() { try { const binding = require('@argos-ci/mask-fingerprint-openharmony-arm') const bindingPackageVersion = require('@argos-ci/mask-fingerprint-openharmony-arm/package.json').version - if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { diff --git a/package.json b/package.json index 570231b..703018b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@argos-ci/mask-fingerprint", - "version": "0.1.2", + "version": "0.1.3", "description": "Fast, deterministic visual diff fingerprinting for PNG images, exposed as a Node.js native module via N-API.", "main": "index.js", "repository": { diff --git a/src/lib.rs b/src/lib.rs index ecce8ac..4163623 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -263,11 +263,17 @@ fn read_next_rgba_row( png: &mut png::Reader, row_out: &mut [u8], width: usize, -) -> napi::Result<()> { - let row = png - .next_row() - .map_err(|e| napi::Error::from_reason(format!("PNG decode error: {e}")))? - .ok_or_else(|| napi::Error::from_reason("PNG ended early"))?; +) -> napi::Result { + let row = match png.next_row() { + Ok(Some(row)) => row, + Ok(None) => return Ok(false), + Err(err) => { + if is_unexpected_eof_decode_error(&err) { + return Ok(false); + } + return Err(napi::Error::from_reason(format!("PNG decode error: {err}"))); + } + }; let data = row.data(); @@ -284,7 +290,17 @@ fn read_next_rgba_row( } row_out.copy_from_slice(data); - Ok(()) + Ok(true) +} + +fn is_unexpected_eof_decode_error(err: &png::DecodingError) -> bool { + match err { + png::DecodingError::IoError(io) => io.kind() == std::io::ErrorKind::UnexpectedEof, + _ => err + .to_string() + .to_lowercase() + .contains("unexpected end of file"), + } } fn fill_mask_row(rgba_row: &[u8], mask_out: &mut [u8], t: RedThreshold) { @@ -462,13 +478,18 @@ fn compute_bbox_streaming( let mut bbox_state = BboxState::new(width, height); - for y in 0..height { - read_next_rgba_row(png, &mut rgba_row, width)?; + let mut y = 0usize; + + while y < height { + if !read_next_rgba_row(png, &mut rgba_row, width)? { + break; + } fill_mask_row(&rgba_row, &mut next, opts.red_threshold); if !have_curr { curr.copy_from_slice(&next); have_curr = true; + y += 1; continue; } @@ -476,6 +497,7 @@ fn compute_bbox_streaming( prev.copy_from_slice(&curr); curr.copy_from_slice(&next); have_prev = true; + y += 1; continue; } @@ -489,22 +511,23 @@ fn compute_bbox_streaming( prev.copy_from_slice(&curr); curr.copy_from_slice(&next); + y += 1; } if have_curr { if have_prev { - if height >= 2 { + if y >= 2 { let ctx = BboxUpdateCtx { - y: height - 2, + y: y - 2, width, dilate_radius: opts.dilate_radius, }; update_bbox_from_dilated_row(&prev, &curr, &next, ctx, &mut bbox_state); } - if height >= 1 { + if y >= 1 { let ctx = BboxUpdateCtx { - y: height - 1, + y: y - 1, width, dilate_radius: opts.dilate_radius, }; @@ -633,13 +656,18 @@ fn accumulate_grid_streaming( dilate_radius: opts.dilate_radius, }; - for y in 0..height { - read_next_rgba_row(png, &mut rgba_row, width)?; + let mut y = 0usize; + + while y < height { + if !read_next_rgba_row(png, &mut rgba_row, width)? { + break; + } fill_mask_row(&rgba_row, &mut next, opts.red_threshold); if !have_curr { curr.copy_from_slice(&next); have_curr = true; + y += 1; continue; } @@ -647,6 +675,7 @@ fn accumulate_grid_streaming( prev.copy_from_slice(&curr); curr.copy_from_slice(&next); have_prev = true; + y += 1; continue; } @@ -654,14 +683,15 @@ fn accumulate_grid_streaming( prev.copy_from_slice(&curr); curr.copy_from_slice(&next); + y += 1; } - if height >= 2 { - accumulate_from_dilated_row(&prev, &curr, &next, height - 2, ctx, &mut counts); + if y >= 2 { + accumulate_from_dilated_row(&prev, &curr, &next, y - 2, ctx, &mut counts); } - if height >= 1 { - accumulate_from_dilated_row(&curr, &next, &next, height - 1, ctx, &mut counts); + if y >= 1 { + accumulate_from_dilated_row(&curr, &next, &next, y - 1, ctx, &mut counts); } Ok(hash_counts_density(