quelda
Version:
PDF & Illustrator security scanner (WebAssembly): files + policy in, verdict out
30 lines (29 loc) • 1.37 kB
JavaScript
// quelda — PDF security scanner (WebAssembly in a Web Worker). Design §8.2.
//
// const scanner = await createScanner();
// const verdict = await scanner.scan(file, { preset: 'strict' });
// if (!verdict.valid) showReasons(verdict.violations);
// scanner.terminate();
import { crossOriginWorkerSource } from './cdn.js';
import { createScannerWith } from './scanner.js';
export { DEFAULT_TIMEOUT_MS, QueldaError, } from './scanner.js';
export * from './types.js';
function defaultWorker() {
if (typeof Worker === 'undefined') {
throw new Error('Web Workers are not available here (quelda runs in browsers; see the README for Node)');
}
const blob = crossOriginWorkerSource(import.meta.url, globalThis.location?.href);
if (blob !== undefined) {
const url = URL.createObjectURL(new Blob([blob], { type: 'text/javascript' }));
return new Worker(url, { type: 'module', name: 'quelda' });
}
// Kept literal so Vite and webpack 5 bundle the worker and its .wasm.
return new Worker(new URL('./worker.js', import.meta.url), { type: 'module', name: 'quelda' });
}
/**
* Starts a Web Worker, loads the WASM engine once and resolves when it is
* ready. Rejects with a {@link QueldaError} if the engine cannot start.
*/
export function createScanner(options) {
return createScannerWith(defaultWorker, options);
}