diff --git a/README.md b/README.md index 223e06d..bf522b7 100644 --- a/README.md +++ b/README.md @@ -251,19 +251,19 @@ Because of this we recommend loading `tesseract.js` from a CDN. But if you reall ```javascript window.Tesseract = Tesseract.create({ workerPath: '/path/to/worker.js', - langPath: 'https://rawcdn.githack.com/naptha/tessdata/gh-pages/3.02/', - corePath: 'https://rawcdn.githack.com/naptha/tesseract.js-core/0.1.0/index.js', + langPath: 'https://cdn.jsdelivr.net/gh/naptha/tessdata@gh-pages/3.02/', + corePath: 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js-core@0.1.0/index.js', }) ``` ### corePath -A string specifying the location of the [tesseract.js-core library](https://github.com/naptha/tesseract.js-core), with default value 'https://rawcdn.githack.com/naptha/tesseract.js-core/master/index.js'. Set this string before calling `Tesseract.recognize` and `Tesseract.detect` if you want Tesseract.js to use a different file. +A string specifying the location of the [tesseract.js-core library](https://github.com/naptha/tesseract.js-core), with default value 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js-core@0.1.0/index.js'. Set this string before calling `Tesseract.recognize` and `Tesseract.detect` if you want Tesseract.js to use a different file. ### workerPath A string specifying the location of the [worker.js](./dist/worker.js) file. Set this string before calling `Tesseract.recognize` and `Tesseract.detect` if you want Tesseract.js to use a different file. ### langPath -A string specifying the location of the tesseract language files, with default value 'https://rawcdn.githack.com/naptha/tessdata/gh-pages/3.02/'. Language file URLs are calculated according to the formula `langPath + langCode + '.traineddata.gz'`. Set this string before calling `Tesseract.recognize` and `Tesseract.detect` if you want Tesseract.js to use different language files. +A string specifying the location of the tesseract language files, with default value 'https://cdn.jsdelivr.net/gh/naptha/tessdata@gh-pages/3.02/'. Language file URLs are calculated according to the formula `langPath + langCode + '.traineddata.gz'`. Set this string before calling `Tesseract.recognize` and `Tesseract.detect` if you want Tesseract.js to use different language files. ## Contributing diff --git a/dist/tesseract.js b/dist/tesseract.js index f703441..e12eed2 100644 --- a/dist/tesseract.js +++ b/dist/tesseract.js @@ -187,7 +187,7 @@ process.umask = function() { return 0; }; },{}],2:[function(require,module,exports){ module.exports={ "name": "tesseract.js", - "version": "1.0.11", + "version": "1.0.12", "description": "Pure Javascript Multilingual OCR", "main": "src/index.js", "scripts": { @@ -236,9 +236,9 @@ module.exports={ 'use strict'; var defaultOptions = { - // workerPath: 'https://rawcdn.githack.com/naptha/tesseract.js/0.2.0/dist/worker.js', - corePath: 'https://rawcdn.githack.com/naptha/tesseract.js-core/0.1.0/index.js', - langPath: 'https://rawcdn.githack.com/naptha/tessdata/gh-pages/3.02/' + // workerPath: 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js@0.2.0/dist/worker.js', + corePath: 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js-core@0.1.0/index.js', + langPath: 'https://cdn.jsdelivr.net/gh/naptha/tessdata@gh-pages/3.02/' }; if (process.env.NODE_ENV === "development") { @@ -246,7 +246,7 @@ if (process.env.NODE_ENV === "development") { defaultOptions.workerPath = location.protocol + '//' + location.host + '/dist/worker.dev.js?nocache=' + Math.random().toString(36).slice(3); } else { var version = require('../../package.json').version; - defaultOptions.workerPath = 'https://rawcdn.githack.com/naptha/tesseract.js/' + version + '/dist/worker.js'; + defaultOptions.workerPath = 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js@' + version + '/dist/worker.js'; } exports.defaultOptions = defaultOptions; diff --git a/package-lock.json b/package-lock.json index f7ca0af..796c592 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "tesseract.js", - "version": "1.0.11", + "version": "1.0.12", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5b3f7a4..e252301 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tesseract.js", - "version": "1.0.11", + "version": "1.0.12", "description": "Pure Javascript Multilingual OCR", "main": "src/index.js", "scripts": { diff --git a/src/browser/index.js b/src/browser/index.js index 9dc256d..f17f378 100644 --- a/src/browser/index.js +++ b/src/browser/index.js @@ -1,7 +1,7 @@ var defaultOptions = { - // workerPath: 'https://rawcdn.githack.com/naptha/tesseract.js/0.2.0/dist/worker.js', - corePath: 'https://rawcdn.githack.com/naptha/tesseract.js-core/0.1.0/index.js', - langPath: 'https://rawcdn.githack.com/naptha/tessdata/gh-pages/3.02/', + // workerPath: 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js@0.2.0/dist/worker.js', + corePath: 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js-core@0.1.0/index.js', + langPath: 'https://cdn.jsdelivr.net/gh/naptha/tessdata@gh-pages/3.02/', } if (process.env.NODE_ENV === "development") { @@ -9,7 +9,7 @@ if (process.env.NODE_ENV === "development") { defaultOptions.workerPath = location.protocol + '//' + location.host + '/dist/worker.dev.js?nocache=' + Math.random().toString(36).slice(3) }else{ var version = require('../../package.json').version; - defaultOptions.workerPath = 'https://rawcdn.githack.com/naptha/tesseract.js/' + version + '/dist/worker.js' + defaultOptions.workerPath = 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js@' + version + '/dist/worker.js' } exports.defaultOptions = defaultOptions; diff --git a/src/node/index.js b/src/node/index.js index 50881cc..d0177dc 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -5,7 +5,7 @@ const fetch = require('isomorphic-fetch'), exports.defaultOptions = { workerPath: require('path').join(__dirname, 'worker.js'), - langPath: 'http://rawcdn.githack.com/naptha/tessdata/gh-pages/3.02/', + langPath: 'https://cdn.jsdelivr.net/gh/naptha/tessdata@gh-pages/3.02/', } exports.spawnWorker = function spawnWorker(instance, workerOptions){ diff --git a/src/node/lang.js b/src/node/lang.js index e452a8b..e06cc20 100644 --- a/src/node/lang.js +++ b/src/node/lang.js @@ -1,4 +1,5 @@ -const http = require("http"), +const https = require("https"), + http = require("http"), zlib = require("zlib"), fs = require("fs"), path = require("path"), @@ -16,10 +17,12 @@ function getLanguageData(req, res, cb){ lang + '.traineddata' : path.join(req.workerOptions.langPath, lang + '.traineddata'); + var fetchProtocol = req.workerOptions.langPath.startsWith('http://') ? http : https; + fs.readFile(localPath, function (err, data) { if(!err) return cb(new Uint8Array(data)); - http.get(req.workerOptions.langPath + langfile, stream => { + fetchProtocol.get(req.workerOptions.langPath + langfile, stream => { var received_bytes = 0; stream.on('data', function(chunk) { received_bytes += chunk.length;