importScripts( "lzma.js", "ctm.js" );

self.onmessage = function( event ) {

	var files = [];

	for ( var i = 0; i < event.data.offsets.length; i ++ ) {

		var stream = new CTM.Stream( event.data.data );
		stream.offset = event.data.offsets[ i ];

		files[ i ] = new CTM.File( stream );

	}

	self.postMessage( files );
	self.close();

};

importScripts( "lzma.js", "ctm.js" );

self.onmessage = function( event ) {

	var files = [];

	for ( var i = 0; i < event.data.offsets.length; i ++ ) {

		var stream = new CTM.Stream( event.data.data );
		stream.offset = event.data.offsets[ i ];

		files[ i ] = new CTM.File( stream, [event.data.data.buffer] );

	}

	self.postMessage( files );
	self.close();

};

Optimize sending data from worker
Optimize sending data from worker

When transferable list is specified, postingMessage to worker doesn't copy data.
Since ctm.js references original data, we can specify original stream to be transferred back to the main thread.