mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-28 15:21:33 +00:00
24 lines
730 B
TypeScript
24 lines
730 B
TypeScript
import { BlobWorker } from 'threads';
|
|
import { fromBase64, toUint8Array } from 'js-base64';
|
|
import type { WorkerImplementation } from 'threads/dist/types/master';
|
|
import { LazyLoader } from '../../interfaces/index.js';
|
|
import { Buffer } from 'buffer';
|
|
|
|
export class InlinedWorkerLoader extends LazyLoader<WorkerImplementation> {
|
|
constructor(b64script: string) {
|
|
super(() => {
|
|
const script = fromBase64(b64script);
|
|
return BlobWorker.fromText(script);
|
|
});
|
|
}
|
|
}
|
|
|
|
export class InlinedWasmLoader extends LazyLoader<Buffer> {
|
|
constructor(b64wasm: string) {
|
|
super(() => {
|
|
const wasm = toUint8Array(b64wasm);
|
|
return Buffer.from(wasm);
|
|
});
|
|
}
|
|
}
|