Browse files

add JS wrapper

  • Loading branch information...
1 parent d41e2c3 commit 5c9a1a23ea18c96d0a894678ef60049bc237230c akdubya committed Dec 12, 2010
Showing with 14 additions and 1 deletion.
  1. +13 −0 index.js
  2. +1 −1 src/binding.cc
View
13 index.js
@@ -1,2 +1,15 @@
var binding = require('./build/default/binding');
+Buffer.prototype.toHex = function() {
+ return binding.bufToHex(this);
+};
+
+Buffer.prototype.writeHex = function(hex) {
+ return binding.hexToBuf(hex, this);
+};
+
+exports.randomBytes = function(len) {
+ var b = new Buffer(len);
+ binding.randomBytes(b);
+ return b;
+};
View
2 src/binding.cc
@@ -119,7 +119,7 @@ Handle<Value> HexToBuf(const Arguments &args) {
extern "C"
void init(Handle<Object> target) {
HandleScope scope;
- target->Set(String::NewSymbol("randBytes"),
+ target->Set(String::NewSymbol("randomBytes"),
FunctionTemplate::New(RandBytes)->GetFunction());
target->Set(String::NewSymbol("bufToHex"),
FunctionTemplate::New(BufToHex)->GetFunction());

0 comments on commit 5c9a1a2

Please sign in to comment.