You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
886 B
36 lines
886 B
/** |
|
* |
|
* Node worker implementation |
|
* |
|
* @fileoverview Node worker implementation |
|
* @author Kevin Kwok <antimatter15@gmail.com> |
|
* @author Guillermo Webster <gui@mit.edu> |
|
* @author Jerome Wu <jeromewus@gmail.com> |
|
*/ |
|
|
|
const check = require('check-types'); |
|
const workerUtils = require('../common/workerUtils'); |
|
|
|
let TesseractCore = null; |
|
|
|
/* |
|
* register message handler |
|
*/ |
|
process.on('message', (packet) => { |
|
workerUtils.dispatchHandlers(packet, obj => process.send(obj)); |
|
}); |
|
|
|
/* |
|
* getCore is a sync function to load and return |
|
* TesseractCore. |
|
*/ |
|
workerUtils.setAdapter({ |
|
getCore: (corePath, res) => { |
|
if (check.null(TesseractCore)) { |
|
res.progress({ status: 'loading tesseract core', progress: 0 }); |
|
TesseractCore = require('tesseract.js-core'); |
|
res.progress({ status: 'loaded tesseract core', progress: 1 }); |
|
} |
|
return TesseractCore; |
|
}, |
|
});
|
|
|