Skip to content

Instantly share code, notes, and snippets.

@azu
Last active September 11, 2020 14:14
Show Gist options
  • Save azu/1949d61a57d0eb896f2a to your computer and use it in GitHub Desktop.
Save azu/1949d61a57d0eb896f2a to your computer and use it in GitHub Desktop.
String to Blob URL for WebWorker
// LICENSE : MIT
"use strict";
window.URL = window.URL || window.webkitURL;
module.exports = function stringToWorkerSrc(src) {
var response = src;
var blob;
try {
blob = new Blob([response], {type: 'application/javascript'});
} catch (e) { // Backwards-compatibility
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
blob = new BlobBuilder();
blob.append(response);
blob = blob.getBlob();
}
return URL.createObjectURL(blob);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment