dataviewstructure
v0.0.2
Published
DataViewStructure is a class that helps fishing binary data structures out of a DataView
Downloads
2
Maintainers
Readme
DataViewStructure
DataViewStructure is a class that allows reading and writing structured data to a DataView.
The struct definition looks like this:
{
fileSignature: 'fourCC'
numTable: 'uint16'
value1: 'int32'
value2: 'int32'
}
You can add types to the DataViewStructure.types object.
Example
const littleEndian=false;
const struct=new DataViewStructure({
sfntVersion: 'fourcc',
numTables: 'uint16',
searchRange: 'uint16',
entrySelector: 'uint16',
rangeShift: 'uint16'
},littleEndian);
const dv=new DataView(new ArryaBuffer(1024));
struct.read(dv,0); // read headers
struct.set('numTables',struct.get('numTables')+1); // manipulate data DataViewStructure extends the Map object
struct.write(dv,0); // writes the changes back to the ArrayBuffer
// (you're then supposed to write the ArrayBuffer back to a file)
TODO
- As of right now there are not enough types to even
cover all of DataView basic capabilities. i.e. no floats.
I implemented this only to parse ttf and otf metadata.
More grunt work on that font is needed. - A cstring and a pascalstring type will be added, though size computation will be an issue.