Easily unpack C Structs and binary buffers

I wrote destruct to tackle the problem of unpacking binary buffers in Node easily. Based off the unpack function in Perl, and inspired by prustat by Brendan Gregg, this module makes it simple to take a binary buffer object, and a format string to unpack values. There were other modules that claimed to have 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.

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.

Check out the project page here https://github.com/bahamas10/node-destruct.git

Usage

var destruct = require('destruct');

Example

var destruct = require('destruct'),
    fs = require('fs');

fs.readFile('/proc/self/psinfo', function(err, buf) {
  console.log(destruct.unpack('iiiiiiiiiiIiiiiSSa8a8a8Z16Z80iiIIaa3iiiiii', buf));
});

yields

[ 33554432,
  3,
  714,
  18456,
  714,
  18456,
  2011,
  2011,
  2300,
  2300,
  0,
  14536,
  9736,
  0,
  1572868,
  11,
  3,
  <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',
  0,
  2,
  134511788,
  134511800,
  <Buffer 01>,
  <Buffer 00 00 00>,
  674523,
  3,
  0,
  0,
  29,
  19167112 ]

Install

npm install destruct

License

MIT Licensed