diff --git a/package.json b/package.json index 54aa999..fa9ec91 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "url": "git://github.com/Topface/node-lzf.git" }, "dependencies": { - "nan": "^2.0.9" + "nan": "^2.18.0" }, "directories": { "lib": "./lib" diff --git a/src/lzf.cc b/src/lzf.cc index d8b769d..ccb113f 100644 --- a/src/lzf.cc +++ b/src/lzf.cc @@ -1,4 +1,5 @@ /* node-lzf (C) 2011 Ian Babrou */ +/* node-lzf (C) 2024 Maintained Türkay Tanrikulu */ #include #include @@ -11,11 +12,9 @@ #include "lzf/lzf.h" - using namespace v8; using namespace node; - // Handle ThrowNodeError(const char* what = NULL) { // return Nan::ThrowError(Exception::Error(Nan::New(what))); // } @@ -27,7 +26,7 @@ NAN_METHOD(compress) { Local bufferIn = info[0]; size_t bytesIn = Buffer::Length(bufferIn); char * dataPointer = Buffer::Data(bufferIn); - size_t bytesCompressed = bytesIn + 100; + size_t bytesCompressed = bytesIn + (bytesIn / 16) + 64 + 3; char * bufferOut = (char*) malloc(bytesCompressed); if (!bufferOut) { @@ -58,7 +57,7 @@ NAN_METHOD(decompress) { size_t bytesUncompressed = 999 * 1024 * 1024; // it's about max size that V8 supports if (info.Length() > 1 && info[1]->IsNumber()) { // accept dest buffer size - bytesUncompressed = info[1]->Uint32Value(); + bytesUncompressed = Nan::To(info[1]).FromJust(); } @@ -79,10 +78,16 @@ NAN_METHOD(decompress) { info.GetReturnValue().Set(BufferOut.ToLocalChecked()); } -extern "C" void -init (Handle target) { - Nan::SetMethod(target, "compress", compress); - Nan::SetMethod(target, "decompress", decompress); +extern "C" void init(Local exports, Local module, Local context) { + Nan::HandleScope scope; + + if (!exports->IsObject() || exports->IsNull()) { + Nan::ThrowTypeError("Target object is not valid"); + return; + } + + Nan::SetMethod(exports.As(), "compress", compress); + Nan::SetMethod(exports.As(), "decompress", decompress); } NODE_MODULE(lzf, init)