ruby array pack and unpack functionality in javascript?
What are the JavaScript functions or libraries that are equivalent to开发者_JAVA百科 Ruby's pack and unpack functions for the Array class? I'm particularly interested in converting hex strings to strings.
irb(main):022:0> ["446f67"].pack("H*")
=> "Dog"
I'm not a JavaScript programmer and would rather not roll my own converter if libraries are available.
I don't think JavaScript has a function that does quite the same thing; pack seems to be a Ruby specific. If you're using pack to turn an object into a string, which can be sent over a network, you could use JSON instead. The Prototype library provides methods for turning objects into JSON-encoded strings. There are also Ruby libraries for working with JSON (encoding and decoding) such as:
http://flori.github.com/json/
answered here: pack / unpack functions for node.js
精彩评论