-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathhelloworld.mjs
More file actions
38 lines (36 loc) · 1.67 KB
/
helloworld.mjs
File metadata and controls
38 lines (36 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { DBR, BarcodeReader } from '../../dist/dbr.js';
import url from 'url'
import fs from 'fs'
// Please visit https://www.dynamsoft.com/customer/license/trialLicense/?product=dbr&utm_source=github&package=js to get trial license.
// If you use nodejs below version 15, please contact [email protected] for a offline trial key of nodejs.
DBR.productKeys = 'PRODUCT-KEYS';
(async()=>{
console.log("============== create reader ==============");
let reader = await BarcodeReader.createInstance();
console.log("============== decode buffer ==============");
let buffer = fs.readFileSync(new URL('../sample.png', import.meta.url));
for(let result of await reader.decode(buffer)){
console.log(result.barcodeText);
}
console.log("============== decode base64 ==============");
let strBase64 = buffer.toString('base64');
for(let result of await reader.decodeBase64String(strBase64)){
console.log(result.barcodeText);
}
console.log("============== decode file ==============");
for(let result of await reader.decode(url.fileURLToPath(new URL('../sample.png', import.meta.url)))){
console.log(result.barcodeText);
}
console.log("============== decode url ==============");
for(let result of await reader.decode('https://demo.dynamsoft.com/barcode-reader/img/AllSupportedBarcodeTypes.png')){
console.log(result.barcodeText);
}
console.log("============== destroy reader ==============");
await reader.destroy();
// Since the worker keep alive, you can call
await DBR._dbrWorker.terminate();
// when you need to exit this process.
// Or call
process.exit();
// directly.
})();