Last active
September 11, 2020 14:14
-
-
Save azu/1949d61a57d0eb896f2a to your computer and use it in GitHub Desktop.
String to Blob URL for WebWorker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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