You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB
JavaScript

'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;
}, {});
};