Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bahamas10/node-destruct
Easily unpack C Structs and binary buffers
https://github.com/bahamas10/node-destruct
Last synced: about 2 months ago
JSON representation
Easily unpack C Structs and binary buffers
- Host: GitHub
- URL: https://github.com/bahamas10/node-destruct
- Owner: bahamas10
- Created: 2012-07-08T08:18:26.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-07-25T19:26:15.000Z (over 12 years ago)
- Last Synced: 2024-10-14T12:49:53.119Z (2 months ago)
- Language: JavaScript
- Size: 107 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
(De) Struct
===========Easily unpack C Structs and binary buffers
Based off the `unpack` function in Perl, and inspired by [prustat][1]
by [Brendan Gregg][2]. 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.Install
------Install locally to use as a module
npm install destruct
Usage
-----as a module
``` js
var destruct = require('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][3] Node module by [@dshaw][4].Functions
---------### destruct.unpack(fmt, buf, [pos])
Unpack a given binary buffer with the given format starting from `pos` (default 0)
Example
-------``` js
var destruct = require('destruct'),
fs = require('fs');fs.readFile('/proc/self/psinfo', function(err, buf) {
console.log(destruct.unpack('iiiiiiiiiiIiiiiSSa8a8a8Z16Z80iiIIaa3iiiiii', buf));
});
```yields
``` js
[ 33554432,
3,
714,
18456,
714,
18456,
2011,
2011,
2300,
2300,
0,
14536,
9736,
0,
1572868,
11,
3,
,
,
,
'node',
'node ./psinfo.js',
0,
2,
134511788,
134511800,
,
,
674523,
3,
0,
0,
29,
19167112 ]
```License
-------MIT Licensed
[1]: http://www.brendangregg.com/DTrace/prustat
[2]: http://www.brendangregg.com
[3]: https://github.com/dshaw/proc
[4]: https://github.com/dshaw