'use strict'; const types = require("./types"); module.exports = function createBufferReader(buffer) { let typeSpecs = { strA: {}, strD: {}, strFilename: {}, int8: { length: 1 }, sint8: { length: 1 }, int16_LSB: { length: 2 }, int16_MSB: { length: 2 }, int16_LSB_MSB: { length: 4 }, sint16_LSB: { length: 2 }, sint16_MSB: { length: 2 }, sint16_LSB_MSB: { length: 4 }, int32_LSB: { length: 4 }, int32_MSB: { length: 4 }, int32_LSB_MSB: { length: 8 }, sint32_LSB: { length: 4 }, sint32_MSB: { length: 4 }, sint32_LSB_MSB: { length: 8 }, decDatetime: { length: 17 }, directoryDatetime: { length: 7 } } return Object.keys(typeSpecs).reduce((methods, type) => { let options = typeSpecs[type]; if (options.length == null) { methods[type] = function(offset, length) { return types[type](buffer.slice(offset, offset + length)); } } else { methods[type] = function(offset) { return types[type](buffer.slice(offset, offset + options.length)); } } return methods; }, {}); };