Use Buffer and data uri when Blob is not available
This commit is contained in:
@@ -151,9 +151,12 @@ function createWorker(config, onMessage) {
|
|||||||
'});',
|
'});',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const blob = new Blob(lines, {type: 'text/javascript'});
|
const worker = new Worker(
|
||||||
const source = URL.createObjectURL(blob);
|
typeof Blob === 'undefined'
|
||||||
const worker = new Worker(source);
|
? 'data:text/javascript;base64,' +
|
||||||
|
Buffer.from(lines.join('\n'), 'binary').toString('base64')
|
||||||
|
: URL.createObjectURL(new Blob(lines, {type: 'text/javascript'}))
|
||||||
|
);
|
||||||
worker.addEventListener('message', onMessage);
|
worker.addEventListener('message', onMessage);
|
||||||
return worker;
|
return worker;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ async function build(input, {minify = true} = {}) {
|
|||||||
return `
|
return `
|
||||||
export function create() {
|
export function create() {
|
||||||
const source = ${JSON.stringify(code)};
|
const source = ${JSON.stringify(code)};
|
||||||
const blob = new Blob([source], {type: 'application/javascript'});
|
return new Worker(typeof Blob === 'undefined'
|
||||||
const url = URL.createObjectURL(blob);
|
? 'data:application/javascript;base64,' + Buffer.from(source, 'binary').toString('base64')
|
||||||
return new Worker(url);
|
: URL.createObjectURL(new Blob([source], {type: 'application/javascript'})));
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user