//! © 2015 Nathan Rugg | MIT /// See LICENSE for more details. // jshint bitwise:true, curly:true, eqeqeq:true, forin:true, immed:true, latedef:true, newcap:true, noarg:true, noempty:true, nonew:true, onevar:true, plusplus:true, quotmark:double, undef:true, unused:strict, browser: true, node: true /// Does the environment support web workers? If not, let's load the worker manually (without polluting the global scope). if (typeof Worker === "undefined" || (typeof location !== "undefined" && location.protocol === "file:")) { /// Is this Node.js? if (typeof global !== "undefined" && typeof require !== "undefined") { this.LZMA = function (lzma_path) { return require(lzma_path || "./lzma_worker.js").LZMA; }; /// Is this a browser? } else if (typeof window !== "undefined" && window.document) { (function () { var that = this, global_var, req = function req(path) { var script_tag = document.createElement("script"); script_tag.type ="text/javascript"; script_tag.src = path; script_tag.onload = function () { /// Make sure this LZMA variable doesn't get overwritten by the worker's. that.LZMA = non_worker_lzma; }; document.getElementsByTagName("head")[0].appendChild(script_tag); }; /// Determine the global variable (it's called "window" in browsers, "global" in Node.js). if (typeof window !== "undefined") { global_var = window; } else if (global) { global_var = global; } function non_worker_lzma(path) { var fake_lzma; req(path); fake_lzma = { compress: function compress(mixed, mode, on_finish, on_progress) { if (global_var.LZMA_WORKER) { global_var.LZMA_WORKER.compress(mixed, mode, on_finish, on_progress); } else { /// Wait setTimeout(function () { fake_lzma.compress(mixed, mode, on_finish, on_progress); }, 50); } }, decompress: function decompress(byte_arr, on_finish, on_progress) { if (global_var.LZMA_WORKER) { global_var.LZMA_WORKER.decompress(byte_arr, on_finish, on_progress); } else { /// Wait setTimeout(function () { fake_lzma.decompress(byte_arr, on_finish, on_progress); }, 50); } }, worker: function worker () { return null; } }; return fake_lzma; } that.LZMA = non_worker_lzma; }()); } else { /// It doesn't seem to be either Node.js or a browser. console.error("Can't load the worker. Sorry."); } } else { /// Let's use Web Workers. ///NOTE: The "this" keyword is the global context ("window" variable) if loaded via a