node-sword-interface 1.0.89 → 1.0.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binding.gyp CHANGED
@@ -88,13 +88,13 @@
88
88
  "src/sword_backend/module_installer.cpp",
89
89
  "src/sword_backend/sword_status_reporter.cpp",
90
90
  "src/sword_backend/text_processor.cpp",
91
+ "src/sword_backend/unzip/unzip.c",
92
+ "src/sword_backend/unzip/ioapi.c",
91
93
  "src/napi_module/install_module_worker.cpp",
92
94
  "src/napi_module/module_search_worker.cpp",
93
95
  "src/napi_module/napi_sword_helper.cpp",
94
96
  "src/napi_module/node_sword_interface.cpp",
95
97
  "src/napi_module/api_lock.cpp",
96
- "src/sword_backend/unzip/unzip.c",
97
- "src/sword_backend/unzip/ioapi.c",
98
98
  "src/napi_module/binding.cpp"
99
99
  ],
100
100
  "conditions":[
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sword-interface",
3
- "version": "1.0.89",
3
+ "version": "1.0.91",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -117,10 +117,19 @@ else
117
117
  # macOS & Linux
118
118
 
119
119
  cd sword_build
120
- cmake -DLIBSWORD_LIBRARY_TYPE=Static -DCMAKE_CXX_STANDARD=11 \
121
- -DCMAKE_BUILD_TYPE=$SWORD_BUILD_TYPE \
122
- -DCMAKE_DISABLE_FIND_PACKAGE_ICU=TRUE \
123
- ../sword
120
+
121
+ if [ "$(uname -s)" = "Darwin" ]; then
122
+ cmake -DLIBSWORD_LIBRARY_TYPE=Static -DCMAKE_CXX_STANDARD=11 \
123
+ -DCMAKE_BUILD_TYPE=$SWORD_BUILD_TYPE \
124
+ -DCMAKE_DISABLE_FIND_PACKAGE_ICU=TRUE \
125
+ -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
126
+ ../sword
127
+ else
128
+ cmake -DLIBSWORD_LIBRARY_TYPE=Static -DCMAKE_CXX_STANDARD=11 \
129
+ -DCMAKE_BUILD_TYPE=$SWORD_BUILD_TYPE \
130
+ -DCMAKE_DISABLE_FIND_PACKAGE_ICU=TRUE \
131
+ ../sword
132
+ fi
124
133
  fi
125
134
 
126
135
  make -j4 sword_static
@@ -39,11 +39,6 @@
39
39
  #include "module_search.hpp"
40
40
  #include "mutex.hpp"
41
41
 
42
- #include <zipcomprs.h>
43
- #include "unzip/unzip.h"
44
- #include <filemgr.h>
45
- #include <fcntl.h>
46
-
47
42
  using namespace std;
48
43
  using namespace sword;
49
44
 
@@ -1041,17 +1036,11 @@ Napi::Value NodeSwordInterface::unTarGZ(const Napi::CallbackInfo& info)
1041
1036
  string filePath = info[0].As<Napi::String>().Utf8Value();
1042
1037
  string destPath = info[1].As<Napi::String>().Utf8Value();
1043
1038
 
1044
- sword::FileDesc* fd = FileMgr::getSystemFileMgr()->open(filePath.c_str(), FileMgr::RDONLY);
1045
- if (!fd) {
1046
- unlockApi();
1047
- return Napi::Boolean::New(env, false);
1048
- }
1049
-
1050
- char ret = ZipCompress::unTarGZ(fd->getFd(), destPath.c_str());
1051
- FileMgr::getSystemFileMgr()->close(fd);
1039
+ FileSystemHelper fsHelper;
1040
+ bool ret = fsHelper.unTarGZ(filePath, destPath);
1052
1041
 
1053
1042
  unlockApi();
1054
- return Napi::Boolean::New(env, ret == 0);
1043
+ return Napi::Boolean::New(env, ret);
1055
1044
  }
1056
1045
 
1057
1046
  Napi::Value NodeSwordInterface::unZip(const Napi::CallbackInfo& info)
@@ -1063,56 +1052,9 @@ Napi::Value NodeSwordInterface::unZip(const Napi::CallbackInfo& info)
1063
1052
  string filePath = info[0].As<Napi::String>().Utf8Value();
1064
1053
  string destPath = info[1].As<Napi::String>().Utf8Value();
1065
1054
 
1066
- unzFile uf = unzOpen(filePath.c_str());
1067
- if (uf == NULL) {
1068
- unlockApi();
1069
- return Napi::Boolean::New(env, false);
1070
- }
1071
-
1072
- int err = unzGoToFirstFile(uf);
1073
- while (err == UNZ_OK) {
1074
- char filename[256];
1075
- unz_file_info file_info;
1076
- err = unzGetCurrentFileInfo(uf, &file_info, filename, sizeof(filename), NULL, 0, NULL, 0);
1077
-
1078
- if (err != UNZ_OK) break;
1079
-
1080
- string fullPath = destPath;
1081
- if (fullPath.back() != '/' && fullPath.back() != '\\') {
1082
- fullPath += '/';
1083
- }
1084
- fullPath += filename;
1085
-
1086
- // Check if directory
1087
- size_t filenameLen = strlen(filename);
1088
- if (filename[filenameLen - 1] == '/') {
1089
- // Create directory
1090
- string dummy = fullPath + "dummy";
1091
- FileMgr::createParent(dummy.c_str());
1092
- } else {
1093
- // It's a file
1094
- FileMgr::createParent(fullPath.c_str());
1095
-
1096
- err = unzOpenCurrentFile(uf);
1097
- if (err == UNZ_OK) {
1098
- sword::FileDesc* fd = FileMgr::getSystemFileMgr()->open(fullPath.c_str(), FileMgr::WRONLY | FileMgr::CREAT | FileMgr::TRUNC);
1099
- if (fd) {
1100
- char buf[4096];
1101
- int readBytes;
1102
- while ((readBytes = unzReadCurrentFile(uf, buf, sizeof(buf))) > 0) {
1103
- FileMgr::write(fd->getFd(), buf, readBytes);
1104
- }
1105
- FileMgr::getSystemFileMgr()->close(fd);
1106
- }
1107
- unzCloseCurrentFile(uf);
1108
- }
1109
- }
1110
-
1111
- err = unzGoToNextFile(uf);
1112
- }
1113
-
1114
- unzClose(uf);
1055
+ FileSystemHelper fsHelper;
1056
+ bool ret = fsHelper.unZip(filePath, destPath);
1115
1057
 
1116
1058
  unlockApi();
1117
- return Napi::Boolean::New(env, true);
1059
+ return Napi::Boolean::New(env, ret);
1118
1060
  }
@@ -42,6 +42,11 @@
42
42
  #include <sstream>
43
43
  #include <vector>
44
44
 
45
+ #include <zipcomprs.h>
46
+ #include "unzip/unzip.h"
47
+ #include <filemgr.h>
48
+ #include <fcntl.h>
49
+
45
50
  #include "file_system_helper.hpp"
46
51
 
47
52
  using namespace std;
@@ -402,4 +407,71 @@ void FileSystemHelper::removeDir(std::string dirName)
402
407
  remove(path);
403
408
  }
404
409
  #endif
405
- #endif
410
+ #endif
411
+
412
+ bool FileSystemHelper::unTarGZ(std::string filePath, std::string destPath)
413
+ {
414
+ sword::FileDesc* fd = sword::FileMgr::getSystemFileMgr()->open(filePath.c_str(), sword::FileMgr::RDONLY);
415
+ if (!fd) {
416
+ return false;
417
+ }
418
+
419
+ char ret = sword::ZipCompress::unTarGZ(fd->getFd(), destPath.c_str());
420
+ sword::FileMgr::getSystemFileMgr()->close(fd);
421
+
422
+ return (ret == 0);
423
+ }
424
+
425
+ bool FileSystemHelper::unZip(std::string filePath, std::string destPath)
426
+ {
427
+ unzFile uf = unzOpen(filePath.c_str());
428
+ if (uf == NULL) {
429
+ return false;
430
+ }
431
+
432
+ int err = unzGoToFirstFile(uf);
433
+ while (err == UNZ_OK) {
434
+ char filename[256];
435
+ unz_file_info file_info;
436
+ err = unzGetCurrentFileInfo(uf, &file_info, filename, sizeof(filename), NULL, 0, NULL, 0);
437
+
438
+ if (err != UNZ_OK) break;
439
+
440
+ string fullPath = destPath;
441
+ if (fullPath.back() != '/' && fullPath.back() != '\\') {
442
+ fullPath += '/';
443
+ }
444
+ fullPath += filename;
445
+
446
+ // Check if directory
447
+ size_t filenameLen = strlen(filename);
448
+ if (filename[filenameLen - 1] == '/') {
449
+ // Create directory
450
+ string dummy = fullPath + "dummy";
451
+ sword::FileMgr::createParent(dummy.c_str());
452
+ } else {
453
+ // It's a file
454
+ sword::FileMgr::createParent(fullPath.c_str());
455
+
456
+ err = unzOpenCurrentFile(uf);
457
+ if (err == UNZ_OK) {
458
+ sword::FileDesc* fd = sword::FileMgr::getSystemFileMgr()->open(fullPath.c_str(), sword::FileMgr::WRONLY | sword::FileMgr::CREAT | sword::FileMgr::TRUNC);
459
+ if (fd) {
460
+ char buf[4096];
461
+ int readBytes;
462
+ while ((readBytes = unzReadCurrentFile(uf, buf, sizeof(buf))) > 0) {
463
+ sword::FileMgr::write(fd->getFd(), buf, readBytes);
464
+ }
465
+ sword::FileMgr::getSystemFileMgr()->close(fd);
466
+ }
467
+ unzCloseCurrentFile(uf);
468
+ }
469
+ }
470
+
471
+ err = unzGoToNextFile(uf);
472
+ }
473
+
474
+ unzClose(uf);
475
+
476
+ return true;
477
+ }
@@ -48,6 +48,8 @@ public:
48
48
  std::string getUserSwordDir();
49
49
  std::string getSystemSwordDir();
50
50
  std::vector<std::string> getFilesInDir(std::string dirName);
51
+ bool unTarGZ(std::string filePath, std::string destPath);
52
+ bool unZip(std::string filePath, std::string destPath);
51
53
  std::string getPathSeparator();
52
54
 
53
55
  bool fileExists(std::string fileName);