function decode(buffer) {
		var file = new Uint8Array(buffer);

		var song = {
			tracks: [],
		};

		var remainder = file;

		while (remainder.length > 0) {
			var type = vtol(remainder.subarray(0, 4));
			var size = vtol(remainder.subarray(4, 8));
			var chunk = remainder.subarray(8, 8 + size);

			console.assert(size == chunk.length, 'chunk length does not match size of chunk data (probably a bad file)');
			handlechunk(song, type, chunk);

			remainder = remainder.subarray(8 + size);
		}

		console.assert(song.numtracks == song.tracks.length, 'number of tracks reported does not match number of tracks read');
		console.assert(!(song.type == 0) || (song.tracks.length == 1), 'type 0 file with num tracks != 1');

		delete song.numtracks; // clear out redundant data
		return song;
	}
/*
	given a serialized file, decode it into a song object
	*/
given a serialized file, decode it into a song object
given a serialized file decode it into a song object
function decode(buffer) {
		var file = new Uint8Array(buffer);
		var song = {
			tracks: [],
		};
		var remainder = file;
		while (remainder.length > 0) {
			var type = vtol(remainder.subarray(0, 4));
			var size = vtol(remainder.subarray(4, 8));
			var chunk = remainder.subarray(8, 8 + size);
			console.assert(size == chunk.length, 'chunk length does not match size of chunk data (probably a bad file)');
			handlechunk(song, type, chunk);
			remainder = remainder.subarray(8 + size);
		}
		console.assert(song.numtracks == song.tracks.length, 'number of tracks reported does not match number of tracks read');
		console.assert(!(song.type == 0) || (song.tracks.length == 1), 'type 0 file with num tracks != 1');
		delete song.numtracks; 
		return song;
	}
function decode ( buffer ) { var file = new Uint8Array ( buffer ) ; var song = { tracks : [ ] , } ; var remainder = file ; while ( remainder . length > 0 ) { var type = vtol ( remainder . subarray ( 0 , 4 ) ) ; var size = vtol ( remainder . subarray ( 4 , 8 ) ) ; var chunk = remainder . subarray ( 8 , 8 + size ) ; console . assert ( size == chunk . length , 'chunk length does not match size of chunk data (probably a bad file)' ) ; handlechunk ( song , type , chunk ) ; remainder = remainder . subarray ( 8 + size ) ; } console . assert ( song . numtracks == song . tracks . length , 'number of tracks reported does not match number of tracks read' ) ; console . assert ( ! ( song . type == 0 ) || ( song . tracks . length == 1 ) , 'type 0 file with num tracks != 1' ) ; delete song . numtracks ; return song ; }
given a serialized file, decode it into a song object
given a serialized file decode it into a song object
// clear out redundant data