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 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": [ diff --git a/src/binding.cc b/src/binding.cc index a7f21f2..05ef48b 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -2,12 +2,13 @@ #include #include "rar.hpp" #include +#include #ifdef _DEBUG #define _D(msg) do {\ std::cout << __FILE__ << ":" << __LINE__ << ">> " << msg << std::endl;\ } while(0) - + #else #define _D(msg) @@ -30,18 +31,18 @@ int _processArchive(int mode, int op, char* filepath, char* toDir, char* passwor 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 +53,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 = 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(Context::GetCurrent()->Global(), argc, argv); + NanMakeCallback(NanGetCurrentContext()->Global(), cb, argc, argv); } else { _D("cb is empty"); } @@ -70,85 +71,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()); +NAN_METHOD(DUMMY) { + NanScope(); + NanReturnUndefined(); } -// processArchive(options, cb) -Handle processArchive(const Arguments& args) { - HandleScope scope; - +NAN_METHOD(processArchive) { + NanScope(); + if (args.Length() < 1) { - ThrowException(Exception::TypeError(String::New("Wrong arguments"))); - return scope.Close(Undefined()); + NanThrowError("Wrong arguments"); + NanReturnUndefined(); } - + int openMode = 0; bool isTest = false; - Local options = args[0]->IsString() ? Object::New() : args[0]->ToObject(); + Local options = args[0]->IsString() ? NanNew() : args[0]->ToObject(); if (args[0]->IsString()) { - options->Set(String::NewSymbol("filepath"), args[0]->ToString()); + options->Set(NanNew("filepath"), args[0]->ToString()); } - Local openModeValue = options->Get(String::NewSymbol("openMode")); + Local openModeValue = options->Get(NanNew("openMode")); if (openModeValue->IsNumber()) { openMode = openModeValue->NumberValue(); } - Local filepathValue = options->Get(String::NewSymbol("filepath")); + Local filepathValue = options->Get(NanNew("filepath")); if (!filepathValue->IsString()) { - ThrowException(Exception::TypeError(String::New("Wrong arguments `filepath`"))); - return scope.Close(Undefined()); + NanThrowError("Wrong arguments `filepath`"); + NanReturnUndefined(); } 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(NanNew("password")); 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 = (args.Length() > 1 && args[1]->IsFunction()) ? args[1].As() : NanNew(DUMMY)->GetFunction(); + + Local isTestValue = options->Get(NanNew("test")); if (!isTestValue->IsUndefined()) { isTest = true; } - - char toDirBuf[1024] = { 0 }; - Local toDirValue = options->Get(String::NewSymbol("toDir")); + + char toDirBuf[1024] = { 0 }; + Local toDirValue = options->Get(NanNew("toDir")); 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()); + NanThrowError("Wrong arguments `toDir` for extract mode"); + NanReturnUndefined(); } } } - - int ret = _processArchive(openMode, isTest ? 1 : (openMode == 0 ? 0 : 2), archiveFilePath, - toDirValue->IsString() ? toDirBuf : NULL, + + int ret = _processArchive(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"))); + NanThrowError("Process archive error"); _D("error code is " << ret); } - return scope.Close(Undefined()); + + NanReturnUndefined(); } void init(Handle exports) { setlocale(LC_ALL,""); - - exports->Set(String::NewSymbol("processArchive"), FunctionTemplate::New(processArchive)->GetFunction()); + exports->Set(NanNew("processArchive"), NanNew(processArchive)->GetFunction()); } NODE_MODULE(unrar, init);