Removed file-type dependency per #711 (#775)

master
Balearica 1 year ago committed by GitHub
parent fd1c8b2dc7
commit 32acbd8579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      package-lock.json
  2. 1
      package.json
  3. 7
      src/worker-script/index.js
  4. 6
      src/worker-script/utils/setImage.js

14
package-lock.json generated

@ -11,7 +11,6 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"bmp-js": "^0.1.0", "bmp-js": "^0.1.0",
"file-type": "^12.4.2",
"idb-keyval": "^6.2.0", "idb-keyval": "^6.2.0",
"is-electron": "^2.2.2", "is-electron": "^2.2.2",
"is-url": "^1.2.4", "is-url": "^1.2.4",
@ -4576,14 +4575,6 @@
"node": "^10.12.0 || >=12.0.0" "node": "^10.12.0 || >=12.0.0"
} }
}, },
"node_modules/file-type": {
"version": "12.4.2",
"resolved": "https://registry.npmjs.org/file-type/-/file-type-12.4.2.tgz",
"integrity": "sha512-UssQP5ZgIOKelfsaB5CuGAL+Y+q7EmONuiwF3N5HAH0t27rvrttgi6Ra9k/+DVaY9UF6+ybxu5pOXLUdA8N7Vg==",
"engines": {
"node": ">=8"
}
},
"node_modules/fill-range": { "node_modules/fill-range": {
"version": "7.0.1", "version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
@ -13051,11 +13042,6 @@
"flat-cache": "^3.0.4" "flat-cache": "^3.0.4"
} }
}, },
"file-type": {
"version": "12.4.2",
"resolved": "https://registry.npmjs.org/file-type/-/file-type-12.4.2.tgz",
"integrity": "sha512-UssQP5ZgIOKelfsaB5CuGAL+Y+q7EmONuiwF3N5HAH0t27rvrttgi6Ra9k/+DVaY9UF6+ybxu5pOXLUdA8N7Vg=="
},
"fill-range": { "fill-range": {
"version": "7.0.1", "version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",

@ -63,7 +63,6 @@
}, },
"dependencies": { "dependencies": {
"bmp-js": "^0.1.0", "bmp-js": "^0.1.0",
"file-type": "^12.4.2",
"idb-keyval": "^6.2.0", "idb-keyval": "^6.2.0",
"is-electron": "^2.2.2", "is-electron": "^2.2.2",
"is-url": "^1.2.4", "is-url": "^1.2.4",

@ -8,7 +8,6 @@
* @author Jerome Wu <jeromewus@gmail.com> * @author Jerome Wu <jeromewus@gmail.com>
*/ */
require('regenerator-runtime/runtime'); require('regenerator-runtime/runtime');
const fileType = require('file-type');
const isURL = require('is-url'); const isURL = require('is-url');
const dump = require('./utils/dump'); const dump = require('./utils/dump');
const isWebWorker = require('../utils/getEnvironment')('type') === 'webworker'; const isWebWorker = require('../utils/getEnvironment')('type') === 'webworker';
@ -125,8 +124,10 @@ res) => {
data = new Uint8Array(data); data = new Uint8Array(data);
const type = fileType(data); // Check for gzip magic numbers (1F and 8B in hex)
if (typeof type !== 'undefined' && type.mime === 'application/gzip') { const isGzip = (data[0] === 31 && data[1] === 139) || (data[1] === 31 && data[0] === 139);
if (isGzip) {
data = adapter.gunzip(data); data = adapter.gunzip(data);
} }

@ -1,5 +1,4 @@
const bmp = require('bmp-js'); const bmp = require('bmp-js');
const fileType = require('file-type');
/** /**
* setImage * setImage
@ -9,7 +8,8 @@ const fileType = require('file-type');
* @access public * @access public
*/ */
module.exports = (TessModule, api, image, angle = 0) => { module.exports = (TessModule, api, image, angle = 0) => {
const type = fileType(image); // Check for bmp magic numbers (42 and 4D in hex)
const isBmp = (image[0] === 66 && image[1] === 77) || (image[1] === 66 && image[0] === 77);
const exif = image.slice(0, 500).toString().match(/\x01\x12\x00\x03\x00\x00\x00\x01\x00(.)/)?.[1]?.charCodeAt(0) || 1; const exif = image.slice(0, 500).toString().match(/\x01\x12\x00\x03\x00\x00\x00\x01\x00(.)/)?.[1]?.charCodeAt(0) || 1;
@ -18,7 +18,7 @@ module.exports = (TessModule, api, image, angle = 0) => {
// * @see https://github.com/DanBloomberg/leptonica/issues/607#issuecomment-1068802516 // * @see https://github.com/DanBloomberg/leptonica/issues/607#issuecomment-1068802516
// * We therefore use bmp-js to convert all bmp files into a format Leptonica is known to support // * We therefore use bmp-js to convert all bmp files into a format Leptonica is known to support
// */ // */
if (type && type.mime === 'image/bmp') { if (isBmp) {
// Not sure what this line actually does, but removing breaks the function // Not sure what this line actually does, but removing breaks the function
const buf = Buffer.from(Array.from({ ...image, length: Object.keys(image).length })); const buf = Buffer.from(Array.from({ ...image, length: Object.keys(image).length }));
const bmpBuf = bmp.decode(buf); const bmpBuf = bmp.decode(buf);

Loading…
Cancel
Save