Browse Source

Fix: allow local node paths for language

pull/141/head
Michael Hadley 8 years ago committed by GitHub
parent
commit
abcb593971
  1. 15
      src/node/lang.js

15
src/node/lang.js

@ -1,15 +1,22 @@ @@ -1,15 +1,22 @@
const http = require("http"),
zlib = require("zlib"),
fs = require("fs"),
path = require("path");
path = require("path"),
isURL = require("is-url");
var langdata = require('../common/langdata.json')
function getLanguageData(req, res, cb){
var lang = req.options.lang,
langfile = lang + '.traineddata.gz';
fs.readFile(lang + '.traineddata', function (err, data) {
// langPath defaults to a URL where languages can be downloaded. If a custom path is specified
// and it is a local path, use that instead
var localPath = isURL(req.workerOptions.langPath) ?
lang + '.traineddata' :
path.join(req.workerOptions.langPath, lang + '.traineddata');
fs.readFile(localPath, function (err, data) {
if(!err) return cb(new Uint8Array(data));
http.get(req.workerOptions.langPath + langfile, stream => {
@ -34,4 +41,4 @@ function getLanguageData(req, res, cb){ @@ -34,4 +41,4 @@ function getLanguageData(req, res, cb){
}
module.exports = getLanguageData;
module.exports = getLanguageData;

Loading…
Cancel
Save