From 7b079af51e658217ccd214c516f8eeb79f0491a5 Mon Sep 17 00:00:00 2001 From: Assaf Arkin Date: Tue, 30 Jun 2015 17:12:43 -0700 Subject: [PATCH 1/3] Switch to Nan for io.js/0.12 compatibility --- binding.gyp | 5 ++- package.json | 7 ++-- src/Crc64.cc | 111 ++++++++++++++++++++++++++++----------------------- src/Crc64.h | 39 ------------------ 4 files changed, 70 insertions(+), 92 deletions(-) delete mode 100644 src/Crc64.h diff --git a/binding.gyp b/binding.gyp index 5e8245c..481b8bb 100644 --- a/binding.gyp +++ b/binding.gyp @@ -5,7 +5,10 @@ "sources": [ "src/crc-64-jones.c", "src/Crc64.cc" - ] + ], + "include_dirs": [ + " -#include -#include - -#include "Crc64.h" +#include "nan.h" using namespace v8; using namespace node; + extern "C" uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l); -void Crc64::Init(Handle exports) { - Local tpl = FunctionTemplate::New(New); - tpl->SetClassName(String::NewSymbol("Crc64")); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->PrototypeTemplate()->Set(String::NewSymbol("push"), FunctionTemplate::New(Push)->GetFunction()); - tpl->PrototypeTemplate()->Set(String::NewSymbol("value"), FunctionTemplate::New(GetValue)->GetFunction()); +class Crc64 : public ObjectWrap { - Persistent constructor = Persistent::New(tpl->GetFunction()); - exports->Set(String::NewSymbol("Crc64"), constructor); -} +public: -Crc64::Crc64() { - crc = 0; -} + static void Init(Handle exports) { + NanScope(); + Local tmpl = NanNew(Crc64::New); + + tmpl->SetClassName(NanNew("Crc64")); + tmpl->InstanceTemplate()->SetInternalFieldCount(1); -Crc64::~Crc64() {} + NODE_SET_PROTOTYPE_METHOD(tmpl, "push", Push); + NODE_SET_PROTOTYPE_METHOD(tmpl, "value", GetValue); -Handle Crc64::New(const Arguments& args) { - if (args.Length() != 0) { - return ThrowException(Exception::Error(String::New("Unexpected arguments"))); - } + NanAssignPersistent(functionTemplate, tmpl); + NanAssignPersistent(constructor, tmpl->GetFunction()); + exports->Set(NanNew("Crc64"), tmpl->GetFunction()); + } + +private: + + Crc64() { + crc = 0; + } - HandleScope scope; - Crc64* obj = new Crc64(); - obj->Wrap(args.This()); - return args.This(); -} + ~Crc64() { + } -Handle Crc64::Push(const Arguments& args) { - if (args.Length() != 1 || !Buffer::HasInstance(args[0])) { - return ThrowException(Exception::Error(String::New("Expecting a single Buffer argument"))); - } + static NAN_METHOD(New) { + NanScope(); + Crc64* instance = new Crc64(); + instance->Wrap(args.This()); + NanReturnThis(); + } - HandleScope scope; - Crc64* obj = ObjectWrap::Unwrap(args.This()); + static NAN_METHOD(Push) { + NanScope(); + if (args.Length() != 1 || !Buffer::HasInstance(args[0])) + return NanThrowError("Expecting a single Buffer argument"); + + Crc64* instance = ObjectWrap::Unwrap(args.Holder()); Local bytes = args[0]->ToObject(); + instance->crc = crc64(instance->crc, (unsigned char *)Buffer::Data(bytes), Buffer::Length(bytes)); + NanReturnUndefined(); + } - obj->crc = crc64(obj->crc, (unsigned char *)Buffer::Data(bytes), Buffer::Length(bytes)); + static NAN_METHOD(GetValue) { + NanScope(); + if (args.Length() != 0) + return NanThrowError("Unexpected arguments"); - return Undefined(); -} + Crc64* instance = ObjectWrap::Unwrap(args.Holder()); + Local BufferOut = NanNewBufferHandle((char*)&(instance->crc), sizeof(uint64_t)); + NanReturnValue(BufferOut); + } -Handle Crc64::GetValue(const Arguments& args) { - if (args.Length() != 0) { - return ThrowException(Exception::Error(String::New("Unexpected arguments"))); - } + static Persistent functionTemplate; + static Persistent constructor; - HandleScope scope; - Crc64* obj = ObjectWrap::Unwrap(args.This()); - Buffer* BufferOut = Buffer::New((char*)&(obj->crc), sizeof(uint64_t)); - return scope.Close(BufferOut->handle_); -} + uint64_t crc; +}; -extern "C" -void init(Handle exports) { + +Persistent Crc64::functionTemplate; +Persistent Crc64::constructor; + + +extern "C" { + + static void init(Handle exports) { Crc64::Init(exports); -} + } -NODE_MODULE(Crc64, init) + NODE_MODULE(Crc64, init) +}; diff --git a/src/Crc64.h b/src/Crc64.h deleted file mode 100644 index f77a4e1..0000000 --- a/src/Crc64.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2013 Danny Yates - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef CRC64_H -#define CRC64_H - -#include -#include - -using namespace node; -using namespace v8; - -class Crc64 : public ObjectWrap { - public: - static void Init(Handle exports); - - private: - Crc64(); - ~Crc64(); - - static Handle New(const Arguments& args); - static Handle Push(const Arguments& args); - static Handle GetValue(const Arguments& args); - - uint64_t crc; -}; - -#endif From 1efd42933a3c67b8b8b4dd44c51db7da171b1b4d Mon Sep 17 00:00:00 2001 From: Assaf Arkin Date: Tue, 30 Jun 2015 17:18:02 -0700 Subject: [PATCH 2/3] Updated 3rd party dependencies to work under io.js/0.12 --- lib/parser.js | 2 +- lib/writer.js | 2 +- package.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index 0d1a8cf..b2e1682 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -17,7 +17,7 @@ var Transform = require('stream').Transform, lzf = require('lzf'), util = require('util'), bufferEqual = require('buffer-equal'), - Int64 = require('int64-native'), + Int64 = require('int64-native-node12'), Crc64 = require('../build/Release/Crc64.node').Crc64; exports = module.exports = Parser; diff --git a/lib/writer.js b/lib/writer.js index 4db310d..54d3810 100644 --- a/lib/writer.js +++ b/lib/writer.js @@ -15,7 +15,7 @@ var Transform = require('stream').Transform, lzf = require('lzf'), util = require('util'), - Int64 = require('int64-native'), + Int64 = require('int64-native-node12'), Crc64 = require('../build/Release/Crc64.node').Crc64; exports = module.exports = Writer; diff --git a/package.json b/package.json index 0196536..4d5fb22 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ ], "dependencies": { "buffer-equal": "0.0.0", - "int64-native": "~0.2.0", - "lzf": "~0.1.3", + "int64-native-node12": "^0.4.0", + "lzf": "git+https://github.com/kieut/node-lzf.git", "nan": "^1.8.4", "stream-parser": "~0.1.0" }, From 663ba74c31def28485a5a4d22eb3b990b75a8e8d Mon Sep 17 00:00:00 2001 From: Assaf Arkin Date: Tue, 21 Jul 2015 11:11:39 -0700 Subject: [PATCH 3/3] 0.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4d5fb22..343e6f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rdb-tools", - "version": "0.1.1", + "version": "0.1.2", "description": "Redis RDB parsing, filtering and creating tools", "author": "Danny Yates ", "licenses": [