I want to generate some binary data in my Node.js application and then write it to an HTTP response for the client to download. My current implementation of the same application is in Python, which achieves this using struct module. For example,
import struct
# ...
s = 'Filename header'
s_binary = struct.pack('15s',s)
# ...
Also, how do I convert numbers into binary in Node.js? The way I do it in Python is:
# To convert a float into four byte binary representation in Python.
import struct
num_binary = struct.pack('f',23.33)
How do I do the same thing in Node.js?
This is so far the best solution I've got - straight port of Python's struct library to Node.js - jspack.