Skip to content

Commit

Permalink
Updated nan from 1.x to 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Sembiance committed Aug 27, 2015
1 parent 703b050 commit a54f19f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
27 changes: 16 additions & 11 deletions mhash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,39 +126,44 @@ hashid get_hash_type_by_name(char * name)

NAN_METHOD(Hash)
{
NanScope();
Local<String> ret;
char * hashed=0;
hashid type;

String::Utf8Value name(args[0]->ToString());
String::Utf8Value name(info[0]->ToString());
type = get_hash_type_by_name(*name);
if(type==(hashid)-1)
NanReturnValue(NanNull());
{
info.GetReturnValue().Set(Nan::Null());
return;
}

if(args[1]->IsString())
if(info[1]->IsString())
{
String::Utf8Value data(args[1]->ToString());
String::Utf8Value data(info[1]->ToString());
hashed = hash(type, (unsigned char *)*data, data.length());
}
else if(node::Buffer::HasInstance(args[1]))
else if(node::Buffer::HasInstance(info[1]))
{
Handle<Object> data = args[1]->ToObject();
Handle<Object> data = info[1]->ToObject();
hashed = hash(type, (unsigned char *)node::Buffer::Data(data), node::Buffer::Length(data));
}

if(!hashed)
NanReturnValue(NanNull());
{
info.GetReturnValue().Set(Nan::Null());
return;
}

ret = NanNew<String>(hashed);
ret = Nan::New(hashed).ToLocalChecked();
free(hashed);

NanReturnValue(ret);
info.GetReturnValue().Set(ret);
}

void Init(Handle<Object> exports)
{
exports->Set(NanNew("hash"), NanNew<FunctionTemplate>(Hash)->GetFunction());
exports->Set(Nan::New("hash").ToLocalChecked(), Nan::New<FunctionTemplate>(Hash)->GetFunction());
}

NODE_MODULE(mhash, Init)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{ "name": "mhash",
"version": "2.0.2",
"version": "2.1.0",
"author": "Robert Schultz <robert@cosmicrealms.com>",
"description": "Provides 27 hashing algorithms: md5, md4, md2, sha1, sha256, whirlpool, crc32, etc. MacOS X requires Xcode to be installed.",
"main": "index",
"dependencies" : { "bindings" : "= 1.2.1", "nan" : "= 1.9.0" },
"dependencies" : { "bindings" : "= 1.2.1", "nan" : "= 2.0.7" },
"engines": { "node": ">= 0.8.0" },
"keywords": [ "hash", "md5", "sha", "crc", "whirlpool", "haval", "ripemd", "gost", "snefru", "alder", "tiger", "crc32", "crc32b", "sha256", "md4", "md2" ],
"homepage" : "http://github.com/Sembiance/mhash",
Expand Down

0 comments on commit a54f19f

Please sign in to comment.