forked from Dynamsoft/barcode-reader-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelloworld.js
More file actions
36 lines (34 loc) · 1.52 KB
/
helloworld.js
File metadata and controls
36 lines (34 loc) · 1.52 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
let DBR = require('../../dist/dbr.js');
// Please visit https://www.dynamsoft.com/customer/license/trialLicense/?product=dbr&utm_source=github&package=js to get trial license.
DBR.BarcodeReader.productKeys = 'PRODUCT-KEYS';
(async()=>{
console.log("============== create reader ==============");
let reader = await DBR.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.BarcodeReader._dbrWorker.terminate();
// when you need to exit this process.
// Or call
process.exit();
// directly.
})();