-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathhelloworld.js
More file actions
37 lines (35 loc) · 1.61 KB
/
helloworld.js
File metadata and controls
37 lines (35 loc) · 1.61 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
let { DBR, BarcodeReader } = require('../../dist/dbr.js');
// 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 fs = require('fs');
let buffer = fs.readFileSync(__dirname + '/../sample.png');
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(__dirname + '/../sample.png')){
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.
})();