Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Support nodejs 13 #13

Merged
merged 1 commit into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/DiffWorkerCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ DiffWorkerCallback::DiffWorkerCallback(Nan::Callback *callback, const std::strin
: AsyncProgressWorkerBase(callback)
{
_oldfile = oldfile;
_newfile = newfile;
_newfile = newfile;
_patchfile = patchfile;
}

DiffWorkerCallback::~DiffWorkerCallback()
DiffWorkerCallback::~DiffWorkerCallback()
{ }

void DiffWorkerCallback::Execute(const ExecutionProgress& progress)
void DiffWorkerCallback::Execute(const ExecutionProgress& progress)
{
char error[1024];
memset(error, 0, sizeof error);
Expand All @@ -51,28 +51,28 @@ void DiffWorkerCallback::Execute(const ExecutionProgress& progress)
data.progressWorker = &progress;

bsdiff(error, _oldfile.c_str(), _newfile.c_str(), _patchfile.c_str(), &data, &DiffWorkerCallback::CCallback);
_error = error;
_error = error;
}

void DiffWorkerCallback::HandleProgressCallback(const int* data, size_t count)
void DiffWorkerCallback::HandleProgressCallback(const int* data, size_t count)
{
if(data != nullptr)
{
Nan::HandleScope scope;
v8::Local<v8::Value> argv[] = {
v8::Number::New(v8::Isolate::GetCurrent(), *data),
v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), _error.c_str())
Nan::New<v8::String>(_error.c_str()).ToLocalChecked()
};

callback->Call(2, argv, this->async_resource);
}
}

void DiffWorkerCallback::HandleOKCallback()
void DiffWorkerCallback::HandleOKCallback()
{
v8::Local<v8::Value> argv[] = {
v8::Local<v8::Value> argv[] = {
v8::Number::New(v8::Isolate::GetCurrent(), 100),
v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), _error.c_str())
Nan::New<v8::String>(_error.c_str()).ToLocalChecked()
};
callback->Call(2, argv, this->async_resource);
}
Expand Down
64 changes: 30 additions & 34 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,46 @@

extern "C" {
#include "c/bsdiff/bsdiff.h"
#include "c/bspatch/bspatch.h"
#include "c/bspatch/bspatch.h"
}

namespace bsdpNode {
using namespace v8;

void diff(const FunctionCallbackInfo<Value>& args)
void diff(const FunctionCallbackInfo<Value>& args)
{
Isolate* isolate = args.GetIsolate();

if(args.Length() < 4 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
if(args.Length() < 4 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
{
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Invalid arguments.")));
Nan::ThrowError("Invalid arguments.");
return;
}

Nan::Callback *callback = new Nan::Callback(args[3].As<v8::Function>());

Nan::Utf8String param0(args[0]);
std::string oldfile = std::string(*param0);
std::string oldfile = std::string(*param0);

Nan::Utf8String param1(args[1]);
std::string newfile = std::string(*param1);
std::string newfile = std::string(*param1);

Nan::Utf8String param2(args[2]);
std::string patchfile = std::string(*param2);
std::string patchfile = std::string(*param2);

DiffWorkerCallback* wc = new DiffWorkerCallback(callback, oldfile, newfile, patchfile);
Nan::AsyncQueueWorker(wc);
}

void diffSync(const FunctionCallbackInfo<Value>& args)
void diffSync(const FunctionCallbackInfo<Value>& args)
{
Isolate* isolate = args.GetIsolate();
HandleScope scope(isolate);
if (!args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())

if (!args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
{
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Invalid arguments.")));
Nan::ThrowError("Invalid arguments.");
return;
}

Nan::Utf8String oldfile(args[0]);
Nan::Utf8String newfile(args[1]);
Nan::Utf8String patchfile(args[2]);
Expand All @@ -79,59 +77,57 @@ namespace bsdpNode {
char error[1024];
memset(error, 0, sizeof error);

int ret = bsdiff(error, *oldfile, *newfile, *patchfile, nullptr, nullptr);
int ret = bsdiff(error, *oldfile, *newfile, *patchfile, nullptr, nullptr);

if(ret != 0)
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, error)));
if(ret != 0)
Nan::ThrowError(error);
}

void patch(const FunctionCallbackInfo<Value>& args)
void patch(const FunctionCallbackInfo<Value>& args)
{
Isolate* isolate = args.GetIsolate();

if(args.Length() < 4 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
if(args.Length() < 4 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
{
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Invalid arguments.")));
Nan::ThrowError("Invalid arguments.");
return;
}

Nan::Callback *callback = new Nan::Callback(args[3].As<v8::Function>());

Nan::Utf8String param0(args[0]);
std::string oldfile = std::string(*param0);
std::string oldfile = std::string(*param0);

Nan::Utf8String param1(args[1]);
std::string newfile = std::string(*param1);
std::string newfile = std::string(*param1);

Nan::Utf8String param2(args[2]);
std::string patchfile = std::string(*param2);
std::string patchfile = std::string(*param2);

PatchWorkerCallback* wc = new PatchWorkerCallback(callback, oldfile, newfile, patchfile);
Nan::AsyncQueueWorker(wc);
}

void patchSync(const FunctionCallbackInfo<Value>& args)
void patchSync(const FunctionCallbackInfo<Value>& args)
{
Isolate* isolate = args.GetIsolate();
HandleScope scope(isolate);

if (!args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
if (!args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
{
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Invalid arguments.")));
Nan::ThrowError("Invalid arguments.");
return;
}

Nan::Utf8String oldfile(args[0]);
Nan::Utf8String newfile(args[1]);
Nan::Utf8String patchfile(args[2]);

char error[1024];
memset(error, 0, sizeof error);

int ret = bspatch(error, *oldfile, *newfile, *patchfile, nullptr, nullptr);
int ret = bspatch(error, *oldfile, *newfile, *patchfile, nullptr, nullptr);

if(ret != 0)
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, error)));
Nan::ThrowError(error);
}

void init(Local<Object> exports, Local<Object> module) {
Expand All @@ -143,4 +139,4 @@ namespace bsdpNode {
}

NODE_MODULE(bsdp, init)
}
}
18 changes: 9 additions & 9 deletions src/PatchWorkerCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ PatchWorkerCallback::PatchWorkerCallback(Nan::Callback *callback, const std::str
: AsyncProgressWorkerBase(callback)
{
_oldfile = oldfile;
_newfile = newfile;
_newfile = newfile;
_patchfile = patchfile;
}

PatchWorkerCallback::~PatchWorkerCallback()
PatchWorkerCallback::~PatchWorkerCallback()
{ }

void PatchWorkerCallback::Execute(const ExecutionProgress& progress)
void PatchWorkerCallback::Execute(const ExecutionProgress& progress)
{
char error[1024];
memset(error, 0, sizeof error);
Expand All @@ -51,28 +51,28 @@ void PatchWorkerCallback::Execute(const ExecutionProgress& progress)
data.progressWorker = &progress;

bspatch(error, _oldfile.c_str(), _newfile.c_str(), _patchfile.c_str(), &data, &PatchWorkerCallback::CCallback);
_error = error;
_error = error;
}

void PatchWorkerCallback::HandleProgressCallback(const int* data, size_t count)
void PatchWorkerCallback::HandleProgressCallback(const int* data, size_t count)
{
if(data != nullptr)
{
Nan::HandleScope scope;
v8::Local<v8::Value> argv[] = {
v8::Number::New(v8::Isolate::GetCurrent(), *data),
v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), _error.c_str())
Nan::New<v8::String>(_error.c_str()).ToLocalChecked()
};

callback->Call(2, argv, this->async_resource);
}
}

void PatchWorkerCallback::HandleOKCallback()
void PatchWorkerCallback::HandleOKCallback()
{
v8::Local<v8::Value> argv[] = {
v8::Local<v8::Value> argv[] = {
v8::Number::New(v8::Isolate::GetCurrent(), 100),
v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), _error.c_str())
Nan::New<v8::String>(_error.c_str()).ToLocalChecked()
};
callback->Call(2, argv, this->async_resource);
}
Expand Down