27

Are there any modules that provide pack / unpack functionality for nodejs similar to python's struct module? I haven't found any specifically for node, and I'd assume that javascript implementations would be significantly slower.

Thanks.

Adam M-W
  • 3,509
  • 9
  • 49
  • 69

3 Answers3

17

https://github.com/pgriess/node-jspack appears to be a straight-up port of Python's struct API for packing binary data, but it's implemented in JS. It doesn't appear to be packaged for npm yet.

https://github.com/substack/node-binary provides unpacking, also implemented in JS, and you can install it with npm install binary if you have npm installed.

clee
  • 10,943
  • 6
  • 36
  • 28
  • No need for a package: http://stackoverflow.com/questions/41655784/php-pack-unpack-implementation-in-javascript-mismatch – KhoPhi Feb 04 '17 at 20:41
  • I've also made https://github.com/natevw/struct-fu which lets you define structures with a C-like feel and pack/unpack them. – natevw Oct 13 '17 at 00:36
11

https://github.com/ryanrolds/bufferpack is another solution

Touv
  • 960
  • 8
  • 10
0

jBinary is another tool in this space which seems to be actively maintained (as of late 2014). It includes sample specifications for a variety of well-known formats, e.g. tar, ico and mp3.

danvk
  • 15,863
  • 5
  • 72
  • 116