开发者

ruby array pack and unpack functionality in javascript?

开发者 https://www.devze.com 2022-12-20 03:33 出处:网络
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 str

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

0

精彩评论

暂无评论...
验证码 换一张
取 消