(De) Struct
Easily unpack C Structs and binary buffers
Based off the unpack
function in Perl, and inspired by prustat
by Brendan Gregg. There were other modules that claimed to do the same functionality,
but most of them were too poorly documented with the source code almost unreadable, while the
others were overcomplicated and didn't support a simple format string.
Install
Install locally to use as a module
npm install destruct
Usage
as a module
var destruct = ;
Known Limitations
This module does not handle all data types, it has only been tested on SmartOS, and was built for making it easier to extend the proc Node module by @dshaw.
Functions
destruct.unpack(fmt, buf, [pos])
Unpack a given binary buffer with the given format starting from pos
(default 0)
Example
var destruct =fs =fmt = 'iiiiiiiiiiIiiiiSSa8a8a8Z16Z80iiIIaa3iiiiii'file = '/proc/self/psinfo';fs;
yields
33554432371418456714184562011201123002300014536973601572868113<Buffer 64 41 f9 4f 3b fe 6c 1a><Buffer 00 00 00 00 35 d5 31 0b><Buffer 00 00 00 00 00 00 00 00>'node''node ./psinfo.js'02134511788134511800<Buffer 01><Buffer 00 00 00>6745233002919167112
License
MIT Licensed