-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbarcode.js
More file actions
38 lines (36 loc) · 1.25 KB
/
Copy pathbarcode.js
File metadata and controls
38 lines (36 loc) · 1.25 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
module.exports = function (RED) {
var dbr = require('barcode4nodejs');
var barcodeTypes = dbr.formats.ALL;
function BarcodeNode(config) {
RED.nodes.createNode(this, config);
this.license = config.license;
this.template = config.template;
var node = this;
node.on('input', function (msg) {
// node.log('msg: ' + JSON.stringify(msg));
if (msg.filename && msg.filename.indexOf('base64') > -1) {
var fs = require('fs');
// Get a license key from https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform
dbr.initLicense(node.license);
fs.readFile(msg.filename, 'utf8', (err, data) => {
dbr.decodeBase64Async(data, barcodeTypes, function (err, results) {
msg.payload = results;
node.send(msg);
}, node.template);
});
}
else if (msg.filename) {
dbr.initLicense(node.license);
dbr.decodeFileAsync(msg.filename, barcodeTypes, function (err, results) {
msg.payload = results;
node.send(msg);
}, node.template);
}
else {
msg.payload = msg.payload.toLowerCase();
node.send(msg);
}
});
}
RED.nodes.registerType('barcode', BarcodeNode);
}