From 2cfe3d83e09ac0f5ca7a83f126b73f29df32421d Mon Sep 17 00:00:00 2001 From: David Roda Date: Sun, 28 Jun 2015 11:33:18 -0400 Subject: [PATCH 1/4] Ignore IDE and build files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 91fa8cf..6cd9977 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /node_modules/ npm-debug.log +build +.idea From b1e03cf44439faf44bc8682cd2fea3ea1c56742b Mon Sep 17 00:00:00 2001 From: David Roda Date: Sun, 28 Jun 2015 11:33:35 -0400 Subject: [PATCH 2/4] Make bindings compatible with v8 0.12 --- src/binding.cc | 96 ++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/src/binding.cc b/src/binding.cc index a7f21f2..75db0bd 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -7,7 +7,7 @@ #define _D(msg) do {\ std::cout << __FILE__ << ":" << __LINE__ << ">> " << msg << std::endl;\ } while(0) - + #else #define _D(msg) @@ -25,23 +25,23 @@ using namespace v8; /// mode: 0 list, 1 extract, 2 list inc split /// op: 0 skip, 1 test, 2 extract -int _processArchive(int mode, int op, char* filepath, char* toDir, char* password, Local cb) { +int _processArchive(Isolate* isolate, int mode, int op, char* filepath, char* toDir, char* password, Local cb) { struct RAROpenArchiveDataEx archiveData; reset_RAROpenArchiveDataEx(&archiveData); archiveData.ArcName = filepath; archiveData.OpenMode = mode; - + HANDLE handler = RAROpenArchiveEx(&archiveData); if (archiveData.OpenResult != ERAR_SUCCESS) { _D("open archive error: " << archiveData.OpenResult); return archiveData.OpenResult; } - - if (password != NULL) { + + if (password != NULL) { _D("password: " << password); RARSetPassword(handler, password); } - + int result = 0; while (result == 0) { struct RARHeaderDataEx entry; @@ -52,13 +52,13 @@ int _processArchive(int mode, int op, char* filepath, char* toDir, char* passwor } if (result != 0) break; - Local entryObj = Object::New(); - entryObj->Set(String::NewSymbol("FileName"), String::New(entry.FileName)); + Local entryObj = Object::New(isolate); + entryObj->Set(String::NewFromUtf8(isolate, "FileName", String::kInternalizedString), String::NewFromUtf8(isolate, entry.FileName)); _D("FileName: " << entry.FileName); if (!cb.IsEmpty()) { const unsigned argc = 1; Local argv[argc] = { entryObj }; - cb->Call(Context::GetCurrent()->Global(), argc, argv); + cb->Call(isolate->GetCurrentContext()->Global(), argc, argv); } else { _D("cb is empty"); } @@ -70,85 +70,83 @@ int _processArchive(int mode, int op, char* filepath, char* toDir, char* passwor return result; } -Handle DUMMY(const Arguments& args) { - HandleScope scope; - - return scope.Close(Undefined()); +void DUMMY(const FunctionCallbackInfo& info) { + } // processArchive(options, cb) -Handle processArchive(const Arguments& args) { - HandleScope scope; - - if (args.Length() < 1) { - ThrowException(Exception::TypeError(String::New("Wrong arguments"))); - return scope.Close(Undefined()); +void processArchive(const FunctionCallbackInfo& info) { + + Isolate* isolate = Isolate::GetCurrent(); + HandleScope scope(isolate); + + if (info.Length() < 1) { + isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments"))); + return; } - + int openMode = 0; bool isTest = false; - Local options = args[0]->IsString() ? Object::New() : args[0]->ToObject(); - if (args[0]->IsString()) { - options->Set(String::NewSymbol("filepath"), args[0]->ToString()); + Local options = info[0]->IsString() ? Object::New(isolate) : info[0]->ToObject(); + if (info[0]->IsString()) { + options->Set(String::NewFromUtf8(isolate, "filepath", String::kInternalizedString), info[0]->ToString()); } - Local openModeValue = options->Get(String::NewSymbol("openMode")); + Local openModeValue = options->Get(String::NewFromUtf8(isolate, "openMode", String::kInternalizedString)); if (openModeValue->IsNumber()) { openMode = openModeValue->NumberValue(); } - Local filepathValue = options->Get(String::NewSymbol("filepath")); + Local filepathValue = options->Get(String::NewFromUtf8(isolate, "filepath", String::kInternalizedString)); if (!filepathValue->IsString()) { - ThrowException(Exception::TypeError(String::New("Wrong arguments `filepath`"))); - return scope.Close(Undefined()); + isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments `filepath`"))); + return; } String::Utf8Value value(filepathValue); const char* filepathStr = (const char*)*value; - char archiveFilePath[2048]; + char archiveFilePath[2048]; strncpy(archiveFilePath, filepathStr, 2048); - - Local passwordValue = options->Get(String::NewSymbol("password")); + + Local passwordValue = options->Get(String::NewFromUtf8(isolate, "password", String::kInternalizedString)); char passwordBuf[128]; if (passwordValue->IsString()) { String::Utf8Value value1(passwordValue); const char* passwordStr = (const char*)*value1; - strncpy(passwordBuf, passwordStr, 128); + strncpy(passwordBuf, passwordStr, 128); } - Local cb = (args.Length()> 1 && args[1]->IsFunction()) ? Local::Cast(args[1]) : FunctionTemplate::New(DUMMY)->GetFunction(); - - Local isTestValue = options->Get(String::NewSymbol("test")); + Local cb = (info.Length()> 1 && info[1]->IsFunction()) ? Local::Cast(info[1]) : FunctionTemplate::New(isolate, DUMMY)->GetFunction(); + + Local isTestValue = options->Get(String::NewFromUtf8(isolate, "test", String::kInternalizedString)); if (!isTestValue->IsUndefined()) { isTest = true; } - - char toDirBuf[1024] = { 0 }; - Local toDirValue = options->Get(String::NewSymbol("toDir")); + + char toDirBuf[1024] = { 0 }; + Local toDirValue = options->Get(String::NewFromUtf8(isolate, "toDir", String::kInternalizedString)); if (openMode == 1) { - if (toDirValue->IsString()) { + if (toDirValue->IsString()) { String::Utf8Value value2(toDirValue); const char* toDirStr = (const char*)*value2; - strncpy(toDirBuf, toDirStr, 1024); + strncpy(toDirBuf, toDirStr, 1024); } else { if (!isTest) { - ThrowException(Exception::TypeError(String::New("Wrong arguments `toDir` for extract mode"))); - return scope.Close(Undefined()); + isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments `toDir` for extract mode"))); + return; } } } - - int ret = _processArchive(openMode, isTest ? 1 : (openMode == 0 ? 0 : 2), archiveFilePath, - toDirValue->IsString() ? toDirBuf : NULL, + + int ret = _processArchive(isolate, openMode, isTest ? 1 : (openMode == 0 ? 0 : 2), archiveFilePath, + toDirValue->IsString() ? toDirBuf : NULL, passwordValue->IsString() ? passwordBuf : NULL, cb); - + if (ret != 0) { - ThrowException(Exception::Error(String::New("Process archive error"))); + isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Process archive error"))); _D("error code is " << ret); } - return scope.Close(Undefined()); } void init(Handle exports) { setlocale(LC_ALL,""); - - exports->Set(String::NewSymbol("processArchive"), FunctionTemplate::New(processArchive)->GetFunction()); + NODE_SET_METHOD(exports, "processArchive", processArchive); } NODE_MODULE(unrar, init); From 50072a9e677bb519c583e0bdaa02d09860d41e77 Mon Sep 17 00:00:00 2001 From: David Roda Date: Sun, 28 Jun 2015 12:28:29 -0400 Subject: [PATCH 3/4] Update bindings to use NAN methods --- src/binding.cc | 61 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/src/binding.cc b/src/binding.cc index 75db0bd..05ef48b 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -2,6 +2,7 @@ #include #include "rar.hpp" #include +#include #ifdef _DEBUG #define _D(msg) do {\ @@ -25,7 +26,7 @@ using namespace v8; /// mode: 0 list, 1 extract, 2 list inc split /// op: 0 skip, 1 test, 2 extract -int _processArchive(Isolate* isolate, int mode, int op, char* filepath, char* toDir, char* password, Local cb) { +int _processArchive(int mode, int op, char* filepath, char* toDir, char* password, Local cb) { struct RAROpenArchiveDataEx archiveData; reset_RAROpenArchiveDataEx(&archiveData); archiveData.ArcName = filepath; @@ -52,13 +53,13 @@ int _processArchive(Isolate* isolate, int mode, int op, char* filepath, char* to } if (result != 0) break; - Local entryObj = Object::New(isolate); - entryObj->Set(String::NewFromUtf8(isolate, "FileName", String::kInternalizedString), String::NewFromUtf8(isolate, entry.FileName)); + Local entryObj = NanNew(); + entryObj->Set(NanNew("FileName"), NanNew(entry.FileName)); _D("FileName: " << entry.FileName); if (!cb.IsEmpty()) { const unsigned argc = 1; Local argv[argc] = { entryObj }; - cb->Call(isolate->GetCurrentContext()->Global(), argc, argv); + NanMakeCallback(NanGetCurrentContext()->Global(), cb, argc, argv); } else { _D("cb is empty"); } @@ -70,57 +71,55 @@ int _processArchive(Isolate* isolate, int mode, int op, char* filepath, char* to return result; } -void DUMMY(const FunctionCallbackInfo& info) { - +NAN_METHOD(DUMMY) { + NanScope(); + NanReturnUndefined(); } -// processArchive(options, cb) -void processArchive(const FunctionCallbackInfo& info) { - - Isolate* isolate = Isolate::GetCurrent(); - HandleScope scope(isolate); +NAN_METHOD(processArchive) { + NanScope(); - if (info.Length() < 1) { - isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments"))); - return; + if (args.Length() < 1) { + NanThrowError("Wrong arguments"); + NanReturnUndefined(); } int openMode = 0; bool isTest = false; - Local options = info[0]->IsString() ? Object::New(isolate) : info[0]->ToObject(); - if (info[0]->IsString()) { - options->Set(String::NewFromUtf8(isolate, "filepath", String::kInternalizedString), info[0]->ToString()); + Local options = args[0]->IsString() ? NanNew() : args[0]->ToObject(); + if (args[0]->IsString()) { + options->Set(NanNew("filepath"), args[0]->ToString()); } - Local openModeValue = options->Get(String::NewFromUtf8(isolate, "openMode", String::kInternalizedString)); + Local openModeValue = options->Get(NanNew("openMode")); if (openModeValue->IsNumber()) { openMode = openModeValue->NumberValue(); } - Local filepathValue = options->Get(String::NewFromUtf8(isolate, "filepath", String::kInternalizedString)); + Local filepathValue = options->Get(NanNew("filepath")); if (!filepathValue->IsString()) { - isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments `filepath`"))); - return; + NanThrowError("Wrong arguments `filepath`"); + NanReturnUndefined(); } String::Utf8Value value(filepathValue); const char* filepathStr = (const char*)*value; char archiveFilePath[2048]; strncpy(archiveFilePath, filepathStr, 2048); - Local passwordValue = options->Get(String::NewFromUtf8(isolate, "password", String::kInternalizedString)); + Local passwordValue = options->Get(NanNew("password")); char passwordBuf[128]; if (passwordValue->IsString()) { String::Utf8Value value1(passwordValue); const char* passwordStr = (const char*)*value1; strncpy(passwordBuf, passwordStr, 128); } - Local cb = (info.Length()> 1 && info[1]->IsFunction()) ? Local::Cast(info[1]) : FunctionTemplate::New(isolate, DUMMY)->GetFunction(); + Local cb = (args.Length() > 1 && args[1]->IsFunction()) ? args[1].As() : NanNew(DUMMY)->GetFunction(); - Local isTestValue = options->Get(String::NewFromUtf8(isolate, "test", String::kInternalizedString)); + Local isTestValue = options->Get(NanNew("test")); if (!isTestValue->IsUndefined()) { isTest = true; } char toDirBuf[1024] = { 0 }; - Local toDirValue = options->Get(String::NewFromUtf8(isolate, "toDir", String::kInternalizedString)); + Local toDirValue = options->Get(NanNew("toDir")); if (openMode == 1) { if (toDirValue->IsString()) { String::Utf8Value value2(toDirValue); @@ -128,25 +127,27 @@ void processArchive(const FunctionCallbackInfo& info) { strncpy(toDirBuf, toDirStr, 1024); } else { if (!isTest) { - isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments `toDir` for extract mode"))); - return; + NanThrowError("Wrong arguments `toDir` for extract mode"); + NanReturnUndefined(); } } } - int ret = _processArchive(isolate, openMode, isTest ? 1 : (openMode == 0 ? 0 : 2), archiveFilePath, + int ret = _processArchive(openMode, isTest ? 1 : (openMode == 0 ? 0 : 2), archiveFilePath, toDirValue->IsString() ? toDirBuf : NULL, passwordValue->IsString() ? passwordBuf : NULL, cb); if (ret != 0) { - isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Process archive error"))); + NanThrowError("Process archive error"); _D("error code is " << ret); } + + NanReturnUndefined(); } void init(Handle exports) { setlocale(LC_ALL,""); - NODE_SET_METHOD(exports, "processArchive", processArchive); + exports->Set(NanNew("processArchive"), NanNew(processArchive)->GetFunction()); } NODE_MODULE(unrar, init); From ee545b26aed7b2ba0010d19e65987cdd700fa7ac Mon Sep 17 00:00:00 2001 From: David Roda Date: Fri, 28 Aug 2015 18:58:47 -0400 Subject: [PATCH 4/4] Update README and package.json for publishing to NPM --- README.md | 9 +++++++++ package.json | 20 +++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0bf9cf4..327d320 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ +## Updated to compile under all versions of NodeJS +Forked from https://github.com/pingjiang/node-rar. + +I needed this module for nodejs >= 0.12. My pull request has been in for many months +with no update and I believe the project may be abandoned, so I published this under +an updated name so I could continue to use it in my projects. If the pull request is +accepted in the original project, or the original project is updated, I will remove +this package and repository. The module now works under all versions of NodeJS. + # Node Rar Addon [![Build Status](https://secure.travis-ci.org/pingjiang/node-rar.png?branch=master)](http://travis-ci.org/pingjiang/node-rar) Node Rar Addon for reading RAR archives using the bundled UnRAR library. diff --git a/package.json b/package.json index bf625b4..d85b25b 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,20 @@ { - "name": "node-rar", - "version": "0.0.2", + "name": "node-rar-updated", + "version": "0.0.1", "main": "lib/rar.js", - "description": "Node Rar Addon for reading RAR archives using the bundled UnRAR library.", - "homepage": "https://github.com/pingjiang/node-rar", - "bugs": "https://github.com/pingjiang/node-rar/issues", + "description": ["Updated Node Rar Addon for reading RAR archives using the ", + "bundled UnRAR library. Works with all versions of NodeJS. Forked from original ", + "node-rar at https://github.com/pingjiang/node-rar"], + "homepage": "https://github.com/davidcroda/node-rar", + "bugs": "https://github.com/davidcroda/node-rar/issues", "author": { - "name": "pingjiang", - "email": "pingjiang1989@gmail.com", - "url": "https://github.com/pingjiang" + "name": "davidcroda", + "email": "davidcroda@gmail.com", + "url": "https://github.com/davidcroda" }, "repository": { "type": "git", - "url": "https://github.com/pingjiang/node-rar" + "url": "https://github.com/davidcroda/node-rar" }, "license": "MIT", "keywords": [