In ruby you can use the String#unpack and Array#pack for these - and many other - transformations.
To change the hex string into the actual bytes, you can put it inside an Array and use Array#pack
like so:
['0001000000000002'].pack 'H*'
# => this will give: "\x00\x01\x00\x00\x00\x00\x00\x02"
What you get is a string with the actual bytes. You can convert this into a byte array using:
data = ['0001000000000002'].pack 'H*'
# => this will give: "\x00\x01\x00\x00\x00\x00\x00\x02"
data.bytes # => [0, 1, 0, 0, 0, 0, 0, 2]
P.S.
The Buffer
class in Javascript is used since pure Javascript isn't binary friendly.
Pure JavaScript is Unicode friendly but not nice to binary data. When dealing with TCP streams or the file system, it's necessary to handle octet streams. Node has several strategies for manipulating, creating, and consuming octet streams.
Raw data is stored in instances of the Buffer class. A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized.
In Ruby, it's possible to use either the String class or an Array to store binary data, so you will not find a designated "Buffer" class.
In Example:
"\x00\x01\x02" # => A string with 3 bytes, using Hex notation (00, 01, 02)
"\x00\x01\x02".bytes # => [1,2,3] An array with 3 bytes.
[1,2,3].pack('C*') # => "\x00\x01\x02" Back to the string
you can also use pack for integers (16bit), longs (32bit) doubles (64bit) and other data types:
[1024, 2].pack('i*') # => "\x00\x04\x00\x00\x02\x00\x00\x00"