src/untar.js
function untar(arrayBuffer) {
	if (!(arrayBuffer instanceof ArrayBuffer)) {
		throw new TypeError("arrayBuffer is not an instance of ArrayBuffer.");
	}

	if (!global.Worker) {
		throw new Error("Worker implementation is not available in this environment.");
	}

	return new ProgressivePromise(function(resolve, reject, progress) {
		var worker = new Worker(workerScriptUri);

		var files = [];

		worker.onerror = function(err) {
			reject(err);
		};

		worker.onmessage = function(message) {
			message = message.data;

			switch (message.type) {
				case "log":
					console[message.data.level]("Worker: " + message.data.msg);
					break;
				case "extract":
					var file = decorateExtractedFile(message.data);
					files.push(file);
					progress(file);
					break;
				case "complete":
					worker.terminate();
					resolve(files);
					break;
				case "error":
					//console.log("error message");
					worker.terminate();
					reject(new Error(message.data.message));
					break;
				default:
					worker.terminate();
					reject(new Error("Unknown message from worker: " + message.type));
					break;
			}
		};

		//console.info("Sending arraybuffer to worker for extraction.");
		worker.postMessage({ type: "extract", buffer: arrayBuffer }, [arrayBuffer]);
	});
}
function untar(arrayBuffer) {
	if (!(arrayBuffer instanceof ArrayBuffer)) {
		throw new TypeError("arrayBuffer is not an instance of ArrayBuffer.");
	}

	if (!global.Worker) {
		throw new Error("Worker implementation is not available in this environment.");
	}

	return new ProgressivePromise(function(resolve, reject, progress) {
		var worker = new Worker(workerScriptUri);

		var files = [];

		worker.onerror = function(err) {
			reject(err);
		};

		worker.onmessage = function(message) {
			message = message.data;

			switch (message.type) {
				case "log":
					console[message.data.level]("Worker: " + message.data.msg);
					break;
				case "extract":
					var file = decorateExtractedFile(message.data);
					files.push(file);
					progress(file);
					break;
				case "complete":
					worker.terminate();
					resolve(files);
					break;
				case "error":
					//console.log("error message");
					worker.terminate();
					reject(new Error(message.data.message));
					break;
				default:
					worker.terminate();
					reject(new Error("Unknown message from worker: " + message.type));
					break;
			}
		};

		//console.info("Sending arraybuffer to worker for extraction.");
		worker.postMessage({ type: "extract", buffer: arrayBuffer }, [arrayBuffer]);
	});
}
function untar ( arrayBuffer ) { if ( ! ( arrayBuffer instanceof ArrayBuffer ) ) { throw new TypeError ( "arrayBuffer is not an instance of ArrayBuffer." ) ; } if ( ! global . Worker ) { throw new Error ( "Worker implementation is not available in this environment." ) ; } return new ProgressivePromise ( function ( resolve , reject , progress ) { var worker = new Worker ( workerScriptUri ) ; var files = [ ] ; worker . onerror = function ( err ) { reject ( err ) ; } ; worker . onmessage = function ( message ) { message = message . data ; switch ( message . type ) { case "log" : console [ message . data . level ] ( "Worker: " + message . data . msg ) ; break ; case "extract" : var file = decorateExtractedFile ( message . data ) ; files . push ( file ) ; progress ( file ) ; break ; case "complete" : worker . terminate ( ) ; resolve ( files ) ; break ; case "error" : //console.log("error message"); worker . terminate ( ) ; reject ( new Error ( message . data . message ) ) ; break ; default : worker . terminate ( ) ; reject ( new Error ( "Unknown message from worker: " + message . type ) ) ; break ; } } ; //console.info("Sending arraybuffer to worker for extraction."); worker . postMessage ( { type : "extract" , buffer : arrayBuffer } , [ arrayBuffer ] ) ; } ) ; }
Returns a ProgressivePromise.
Returns a ProgressivePromise .