Skip to content

Commit

Permalink
Merge pull request #1180 from siiky/fix/lam-1062/pdf417-parsing
Browse files Browse the repository at this point in the history
LAM-1062 fix: PDF417 parsing
  • Loading branch information
RafaelTaranto authored Sep 12, 2024
2 parents 61d8e52 + 1e66f2f commit a91f6f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
24 changes: 8 additions & 16 deletions lib/compliance/parsepdf417.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module.exports = {parse}

const crypto = require('crypto')

const _ = require('lodash/fp')

const parsers = [
require('./parsepdf417-us'),
require('./parsepdf417-ca-bc'),
Expand All @@ -16,19 +14,13 @@ function generateUID (subfile) {
}

function parse (data) {
let result = null

const dataStr = data.toString()

const singleParse = parser => {
const r = parser.parse(dataStr)
if (!r) return true

result = r
return false
data = data.toString()
const result = parsers
.map(parser => parser.parse(data))
.find(result => !!result) || null
if (result) {
result.uid = generateUID(data)
result.raw = data
}

_.forEach(singleParse, parsers)

return _.set('uid', generateUID(dataStr), result)
return result
}
7 changes: 2 additions & 5 deletions lib/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,10 @@ const scanPDF417 = (callback, idCardStillsCallback) => {
return result
})
.then(result => Promise.all([
result,
Pdf417Parser.parse(result),
result ? Pdf417Parser.parse(result) : null,
saveFailedScans(tmpdirs)
]))
.then(([result, parsed, _]) => {
parsed = parsed || null
if (parsed) parsed.raw = result.toString()
.then(([parsed, _]) => {
callback(null, parsed)
})
.catch(err => {
Expand Down

0 comments on commit a91f6f7

Please sign in to comment.