Browse Source

Merge pull request #244 from jeromewu/master

Use jsDelivr as cdn
pull/246/head
jeromewu 6 years ago committed by GitHub
parent
commit
a4f69237a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      README.md
  2. 10
      dist/tesseract.js
  3. 2
      package-lock.json
  4. 2
      package.json
  5. 8
      src/browser/index.js
  6. 2
      src/node/index.js
  7. 7
      src/node/lang.js

8
README.md

@ -251,19 +251,19 @@ Because of this we recommend loading `tesseract.js` from a CDN. But if you reall @@ -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

10
dist/tesseract.js vendored

@ -187,7 +187,7 @@ process.umask = function() { return 0; }; @@ -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={ @@ -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") { @@ -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;

2
package-lock.json generated

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
{
"name": "tesseract.js",
"version": "1.0.11",
"version": "1.0.12",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

2
package.json

@ -1,6 +1,6 @@ @@ -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": {

8
src/browser/index.js

@ -1,7 +1,7 @@ @@ -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") { @@ -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;

2
src/node/index.js

@ -5,7 +5,7 @@ const fetch = require('isomorphic-fetch'), @@ -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){

7
src/node/lang.js

@ -1,4 +1,5 @@ @@ -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){ @@ -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;

Loading…
Cancel
Save