UNPKG

dynamsoft-capture-vision-for-node

Version:

Dynamsoft Capture Vision (DCV) is a comprehensive SDK that integrates various functional products. It encompasses image capture, content understanding, result parsing, and interactive workflow. Essentially, DCV processes images to extract specific informa

2 lines (1 loc) 2.65 kB
"use strict";var e=require("node:path"),t=require("node:fs"),r=require("node:url"),s=require("node:worker_threads"),a=require("koffi"),i="undefined"!=typeof document?document.currentScript:null;const n=e.resolve("undefined"!=typeof __dirname?__dirname:r.fileURLToPath(("undefined"==typeof document?require("url").pathToFileURL(__filename).href:i&&"SCRIPT"===i.tagName.toUpperCase()&&i.src||new URL("worker.js",document.baseURI).href)+"/../"),"../"),o="darwin"===process.platform?"universal2":process.arch;let c=`dynamsoft-capture-vision-for-node-lib-${process.platform}-${o}`;c=t.existsSync(e.resolve(n,"node_modules",c))?e.resolve(n,"node_modules",c):e.resolve(n,"../",c);let l="dcv-nodejs-wrapper.";switch(process.platform){case"win32":l+="dll";break;case"linux":l="lib"+l+"so";break;case"darwin":l="lib"+l+"dylib";break;default:throw Error("`dynamsoft capture vision for nodejs` not support this platfrom.")}const d=a.load(e.resolve(c,l)),u=d.func("dcvnodejs_captureImagedata","str",["intptr","int","uint8*","int","int","int","int","int","str"]),p=d.func("dcvnodejs_captureFileInMemory","str",["intptr","uint8*","int","str"]),m=d.func("dcvnodejs_captureFileInDisk","str",["intptr","str","str"]),f=d.func("dcvnodejs_captureMultiPagesFileInMemory","str",["intptr","uint8*","int","str"]),y=d.func("dcvnodejs_captureMultiPagesFileInDisk","str",["intptr","str","str"]),h={captureImagedata:(e,t,r)=>{try{let s=u(r,e.imageData.bytes.length,e.imageData.bytes,e.imageData.width,e.imageData.height,e.imageData.stride,e.imageData.format,e.imageData.orientation||1,e.templateName);g(t,{success:!0,strRep:s})}catch(e){return void v(t,e)}},captureFileInMemory:(e,t,r)=>{try{let s=p(r,e.fileBytes,e.fileBytes.length,e.templateName);g(t,{success:!0,strRep:s})}catch(e){return void v(t,e)}},captureFileInDisk:(e,t,r)=>{try{let s=m(r,e.filePath,e.templateName);g(t,{success:!0,strRep:s})}catch(e){return void v(t,e)}},captureMultiPagesFileInMemory:(e,t,r)=>{try{let s=f(r,e.fileBytes,e.fileBytes.length,e.templateName);g(t,{success:!0,strRep:s})}catch(e){return void v(t,e)}},captureMultiPagesFileInDisk:(e,t,r)=>{try{let s=y(r,e.filePath,e.templateName);g(t,{success:!0,strRep:s})}catch(e){return void v(t,e)}}};s.parentPort.on("message",(e=>{const t=e.data?e.data:e,r=t.body,s=t.id,a=t.instanceID,i=h[t.type];if(!i)throw new Error("Unmatched task: "+t.type);i(r,s,a)}));const g=(e,t)=>{s.parentPort.postMessage({type:"task",id:e,body:Object.assign({success:!0},t)})},v=(e,t)=>{s.parentPort.postMessage({type:"task",id:e,body:{success:!1,message:(null==t?void 0:t.message)||"No have error message.",stack:(null==t?void 0:t.stack)||"No have error message."}})};