Skip to content
Open
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
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ matrix:
#compiler: clang
#env: NODE_VERSION="4" COVERAGE=true # node abi 46
# Linux
- os: linux
compiler: clang
env: NODE_VERSION="12" # node abi 72
- os: linux
compiler: clang
env: NODE_VERSION="10" # node abi 64
Expand All @@ -25,6 +28,9 @@ matrix:
compiler: clang
env: NODE_VERSION="6" # node abi 48
# OS X
- os: osx
compiler: clang
env: NODE_VERSION="12" # node abi 72
- os: osx
compiler: clang
env: NODE_VERSION="10" # node abi 64
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"BSD"
],
"dependencies": {
"nan": "~2.10.0",
"nan": "~2.14.0",
"node-pre-gyp": "~0.10.2"
},
"devDependencies": {
Expand Down
46 changes: 24 additions & 22 deletions src/node_zipfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern "C" {
#include <fstream>
#include <stdexcept>

#define TOSTR(obj) (*String::Utf8Value((obj)->ToString()))
#define TOSTR(obj) (*Nan::Utf8String(Nan::To<v8::String>(obj).ToLocalChecked()))

using namespace v8;

Expand All @@ -42,7 +42,7 @@ void ZipFile::Initialize(Local<Object> target) {
Nan::SetAccessor(lcons->InstanceTemplate(), Nan::New("count").ToLocalChecked(), get_prop);
Nan::SetAccessor(lcons->InstanceTemplate(), Nan::New("names").ToLocalChecked(), get_prop);

target->Set(Nan::New("ZipFile").ToLocalChecked(),lcons->GetFunction());
Nan::Set(target, Nan::New("ZipFile").ToLocalChecked(), Nan::GetFunction(lcons).ToLocalChecked());
constructor.Reset(lcons);
}

Expand Down Expand Up @@ -109,7 +109,7 @@ void ZipFile::get_prop(v8::Local<v8::String> property, const Nan::PropertyCallba
unsigned num = zf->names_.size();
Local<Array> a = Nan::New<Array>(num);
for (unsigned i = 0; i < num; ++i) {
a->Set(i, Nan::New(zf->names_[i].c_str()).ToLocalChecked());
Nan::Set(a, i, Nan::New(zf->names_[i].c_str()).ToLocalChecked());
}
args.GetReturnValue().Set(a);
} else {
Expand Down Expand Up @@ -264,15 +264,17 @@ void ZipFile::Work_CopyFile(uv_work_t* req) {
}
}

void ZipFile::Work_AfterCopyFile(uv_work_t* req) {
void ZipFile::Work_AfterCopyFile(uv_work_t* req, int status) {
Nan::HandleScope scope;
copy_file_baton *closure = static_cast<copy_file_baton *>(req->data);
if (!closure->error_name.empty()) {
Nan::AsyncResource ar("ZipFile::Work_AfterCopyFile");
Local<Value> argv[1] = { Nan::Error(closure->error_name.c_str()) };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv);
ar.runInAsyncScope(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv);
} else {
Nan::AsyncResource ar("ZipFile::Work_AfterCopyFile");
Local<Value> argv[1] = { Nan::Null() };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv);
ar.runInAsyncScope(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv);
}
closure->zf->Unref();
closure->cb.Reset();
Expand Down Expand Up @@ -462,18 +464,20 @@ void ZipFile::Work_ReadFile(uv_work_t* req) {
}
}

void ZipFile::Work_AfterReadFile(uv_work_t* req) {
void ZipFile::Work_AfterReadFile(uv_work_t* req, int status) {
Nan::HandleScope scope;

closure_t *closure = static_cast<closure_t *>(req->data);

if (closure->error) {
Nan::AsyncResource ar("ZipFile::Work_AfterReadFile");
Local<Value> argv[1] = { Nan::Error(closure->error_name.c_str()) };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv);
ar.runInAsyncScope(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv);
} else {
Nan::AsyncResource ar("ZipFile::Work_AfterReadFile");
Local<Object> retbuf = Nan::CopyBuffer(reinterpret_cast<char *>(&closure->data[0]), closure->data.size()).ToLocalChecked();
Local<Value> argv[2] = { Nan::Null(), retbuf };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv);
ar.runInAsyncScope(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv);
}

if (closure->za) zip_close(closure->za);
Expand All @@ -482,19 +486,17 @@ void ZipFile::Work_AfterReadFile(uv_work_t* req) {
delete closure;
}

extern "C" {
static void init(Local<Object> target) {
ZipFile::Initialize(target);
NAN_MODULE_INIT(init) {
ZipFile::Initialize(target);

// node-zipfile version
target->Set(Nan::New("version").ToLocalChecked(), Nan::New("0.5.8").ToLocalChecked());
// node-zipfile version
Nan::Set(target, Nan::New("version").ToLocalChecked(), Nan::New("0.5.8").ToLocalChecked());

// versions of deps
Local<Object> versions = Nan::New<Object>();
versions->Set(Nan::New("node").ToLocalChecked(), Nan::New(NODE_VERSION+1).ToLocalChecked());
versions->Set(Nan::New("v8").ToLocalChecked(), Nan::New(V8::GetVersion()).ToLocalChecked());
target->Set(Nan::New("versions").ToLocalChecked(), versions);
}
#define MAKE_MODULE(_modname) NODE_MODULE( _modname, init)
MAKE_MODULE(MODULE_NAME)
// versions of deps
Local<Object> versions = Nan::New<Object>();
Nan::Set(versions, Nan::New("node").ToLocalChecked(), Nan::New(NODE_VERSION+1).ToLocalChecked());
Nan::Set(versions, Nan::New("v8").ToLocalChecked(), Nan::New(V8::GetVersion()).ToLocalChecked());
Nan::Set(target, Nan::New("versions").ToLocalChecked(), versions);
}

NAN_MODULE_WORKER_ENABLED(zipfile, init);
4 changes: 2 additions & 2 deletions src/node_zipfile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class ZipFile: public node::ObjectWrap {
static void get_prop(v8::Local<v8::String> property, const Nan::PropertyCallbackInfo<v8::Value>& args);
static void copyFile(const Nan::FunctionCallbackInfo<v8::Value>& args);
static void Work_CopyFile(uv_work_t* req);
static void Work_AfterCopyFile(uv_work_t* req);
static void Work_AfterCopyFile(uv_work_t* req, int status);
static void copyFileSync(const Nan::FunctionCallbackInfo<v8::Value>& args);
static void readFileSync(const Nan::FunctionCallbackInfo<v8::Value>& args);
static void readFile(const Nan::FunctionCallbackInfo<v8::Value>& args);
static void Work_ReadFile(uv_work_t* req);
static void Work_AfterReadFile(uv_work_t* req);
static void Work_AfterReadFile(uv_work_t* req, int status);
ZipFile(std::string const& file_name);
std::vector<std::string> const& names() const { return names_; }
std::string const& file_name() const { return file_name_; }
Expand Down