var CONSTANTS = require("./constants"); function parser(arrayBuffer) { var data = {}; var i = 0; var arr = new Int8Array(arrayBuffer); // Parse header data.type = String.fromCharCode.apply( null, arr.slice(i, CONSTANTS.HEADER.length) ); if (data.type !== CONSTANTS.HEADER) { throw new Error("Invalid .eqf file."); } i += CONSTANTS.HEADER.length; // Skip "!--" i += 4; // Get the presets data.presets = []; while (i < arr.length) { var preset = {}; // Get the name var nameStart = i; var nameEnd = nameStart + 257; // Str is fixed length // Str is null terminated while (arr[i] !== 0 && i <= nameEnd) { i++; } preset.name = String.fromCharCode.apply(null, arr.slice(nameStart, i)); i = nameEnd; // Skip over any unused bytes // Get the levels CONSTANTS.PRESET_VALUES.forEach(function(valueName) { preset[valueName] = 64 - arr[i++]; // Adjust for inverse values }); data.presets.push(preset); } return data; } module.exports = parser;