diff --git a/src/createWorker.js b/src/createWorker.js index 11708cc..83dd6e6 100644 --- a/src/createWorker.js +++ b/src/createWorker.js @@ -59,6 +59,38 @@ module.exports = (_options = {}) => { })) ); + const writeText = (path, text, jobId) => ( + startJob(createJob({ + id: jobId, + action: 'FS', + payload: { method: 'writeFile', args: [path, text] }, + })) + ); + + const readText = (path, jobId) => ( + startJob(createJob({ + id: jobId, + action: 'FS', + payload: { method: 'readFile', args: [path, { encoding: 'utf8' }] }, + })) + ); + + const removeText = (path, jobId) => ( + startJob(createJob({ + id: jobId, + action: 'FS', + payload: { method: 'unlink', args: [path] }, + })) + ); + + const FS = (method, args, jobId) => ( + startJob(createJob({ + id: jobId, + action: 'FS', + payload: { method, args }, + })) + ); + const loadLanguage = (langs = 'eng', jobId) => ( startJob(createJob({ id: jobId, @@ -151,6 +183,10 @@ module.exports = (_options = {}) => { setResolve, setReject, load, + writeText, + readText, + removeText, + FS, loadLanguage, initialize, setParameters, diff --git a/src/index.d.ts b/src/index.d.ts index e73daea..2a7f265 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -15,6 +15,10 @@ declare namespace Tesseract { interface Worker { load(jobId?: string): Promise + writeText(path: string, text: string, jobId?: string): Promise + readText(path: string, jobId?: string): Promise + removeText(path: string, jobId?: string): Promise + FS(method: string, args: any[], jobId?: string): Promise loadLanguage(langs?: string, jobId?: string): Promise initialize(langs?: string, oem?: OEM, jobId?: string): Promise setParameters(params: Partial, jobId?: string): Promise diff --git a/src/worker-script/index.js b/src/worker-script/index.js index c090416..d26a5e7 100644 --- a/src/worker-script/index.js +++ b/src/worker-script/index.js @@ -54,6 +54,11 @@ const load = ({ workerId, jobId, payload: { options: { corePath, logging } } }, } }; +const FS = ({ workerId, payload: { method, args } }, res) => { + log(`[${workerId}]: FS.${method} with args ${args}`); + res.resolve(TessModule.FS[method](...args)); +}; + const loadLanguage = async ({ workerId, payload: { @@ -280,6 +285,7 @@ exports.dispatchHandlers = (packet, send) => { try { ({ load, + FS, loadLanguage, initialize, setParameters,