node-sword-interface 1.0.87 → 1.0.89
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/API.md +28 -0
- package/binding.gyp +3 -1
- package/index.js +20 -0
- package/package.json +1 -1
- package/scripts/build_sword.sh +9 -1
- package/src/napi_module/node_sword_interface.cpp +93 -1
- package/src/napi_module/node_sword_interface.hpp +2 -0
- package/src/sword_backend/unzip/ioapi.c +257 -0
- package/src/sword_backend/unzip/ioapi.h +210 -0
- package/src/sword_backend/unzip/unzip.c +2128 -0
- package/src/sword_backend/unzip/unzip.h +437 -0
package/API.md
CHANGED
|
@@ -79,6 +79,8 @@ This is the main class of node-sword-interface and it provides a set of static f
|
|
|
79
79
|
* [.isModuleAvailableInRepo(moduleCode)](#NodeSwordInterface+isModuleAvailableInRepo) ⇒ <code>Boolean</code>
|
|
80
80
|
* [.getSwordTranslation(originalString, localeCode)](#NodeSwordInterface+getSwordTranslation)
|
|
81
81
|
* [.getBookAbbreviation(moduleName, bookCode, localeCode)](#NodeSwordInterface+getBookAbbreviation)
|
|
82
|
+
* [.unTarGZ(filePath, destPath)](#NodeSwordInterface+unTarGZ) ⇒ <code>Boolean</code>
|
|
83
|
+
* [.unZip(filePath, destPath)](#NodeSwordInterface+unZip) ⇒ <code>Boolean</code>
|
|
82
84
|
* [.getSwordVersion()](#NodeSwordInterface+getSwordVersion) ⇒ <code>String</code>
|
|
83
85
|
* [.getSwordPath()](#NodeSwordInterface+getSwordPath) ⇒ <code>String</code>
|
|
84
86
|
|
|
@@ -643,6 +645,32 @@ Uses the Sword LocaleMgr to translate a book abbreviation.
|
|
|
643
645
|
| bookCode | <code>String</code> |
|
|
644
646
|
| localeCode | <code>String</code> |
|
|
645
647
|
|
|
648
|
+
<a name="NodeSwordInterface+unTarGZ"></a>
|
|
649
|
+
|
|
650
|
+
### nodeSwordInterface.unTarGZ(filePath, destPath) ⇒ <code>Boolean</code>
|
|
651
|
+
Extracts a tar.gz file to a destination path.
|
|
652
|
+
|
|
653
|
+
**Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
|
|
654
|
+
**Returns**: <code>Boolean</code> - True if successful, false otherwise.
|
|
655
|
+
|
|
656
|
+
| Param | Type | Description |
|
|
657
|
+
| --- | --- | --- |
|
|
658
|
+
| filePath | <code>String</code> | The path to the tar.gz file. |
|
|
659
|
+
| destPath | <code>String</code> | The destination path where the file should be extracted. |
|
|
660
|
+
|
|
661
|
+
<a name="NodeSwordInterface+unZip"></a>
|
|
662
|
+
|
|
663
|
+
### nodeSwordInterface.unZip(filePath, destPath) ⇒ <code>Boolean</code>
|
|
664
|
+
Extracts a zip file to a destination path.
|
|
665
|
+
|
|
666
|
+
**Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
|
|
667
|
+
**Returns**: <code>Boolean</code> - True if successful, false otherwise.
|
|
668
|
+
|
|
669
|
+
| Param | Type | Description |
|
|
670
|
+
| --- | --- | --- |
|
|
671
|
+
| filePath | <code>String</code> | The path to the zip file. |
|
|
672
|
+
| destPath | <code>String</code> | The destination path where the file should be extracted. |
|
|
673
|
+
|
|
646
674
|
<a name="NodeSwordInterface+getSwordVersion"></a>
|
|
647
675
|
|
|
648
676
|
### nodeSwordInterface.getSwordVersion() ⇒ <code>String</code>
|
package/binding.gyp
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
'message': 'Building sword library for iOS...',
|
|
22
22
|
'inputs': [],
|
|
23
23
|
'outputs': ['sword_build/libsword.a'],
|
|
24
|
-
'action': ['./scripts/build_sword.sh', '--ios', '${PLATFORM_NAME}', '<(ios_ver)'],
|
|
24
|
+
'action': ['./scripts/build_sword.sh', '--ios', '${PLATFORM_NAME}', '<(ios_ver)', '${ARCHS}'],
|
|
25
25
|
}
|
|
26
26
|
]
|
|
27
27
|
}],
|
|
@@ -93,6 +93,8 @@
|
|
|
93
93
|
"src/napi_module/napi_sword_helper.cpp",
|
|
94
94
|
"src/napi_module/node_sword_interface.cpp",
|
|
95
95
|
"src/napi_module/api_lock.cpp",
|
|
96
|
+
"src/sword_backend/unzip/unzip.c",
|
|
97
|
+
"src/sword_backend/unzip/ioapi.c",
|
|
96
98
|
"src/napi_module/binding.cpp"
|
|
97
99
|
],
|
|
98
100
|
"conditions":[
|
package/index.js
CHANGED
|
@@ -754,6 +754,26 @@ class NodeSwordInterface {
|
|
|
754
754
|
return this.nativeInterface.getBookAbbreviation(moduleName, bookCode, localeCode);
|
|
755
755
|
}
|
|
756
756
|
|
|
757
|
+
/**
|
|
758
|
+
* Extracts a tar.gz file to a destination path.
|
|
759
|
+
* @param {String} filePath - The path to the tar.gz file.
|
|
760
|
+
* @param {String} destPath - The destination path where the file should be extracted.
|
|
761
|
+
* @return {Boolean} True if successful, false otherwise.
|
|
762
|
+
*/
|
|
763
|
+
unTarGZ(filePath, destPath) {
|
|
764
|
+
return this.nativeInterface.unTarGZ(filePath, destPath);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Extracts a zip file to a destination path.
|
|
769
|
+
* @param {String} filePath - The path to the zip file.
|
|
770
|
+
* @param {String} destPath - The destination path where the file should be extracted.
|
|
771
|
+
* @return {Boolean} True if successful, false otherwise.
|
|
772
|
+
*/
|
|
773
|
+
unZip(filePath, destPath) {
|
|
774
|
+
return this.nativeInterface.unZip(filePath, destPath);
|
|
775
|
+
}
|
|
776
|
+
|
|
757
777
|
/**
|
|
758
778
|
* Returns the version of the SWORD library
|
|
759
779
|
* @return {String} SWORD library version.
|
package/package.json
CHANGED
package/scripts/build_sword.sh
CHANGED
|
@@ -85,11 +85,19 @@ elif [ "$1" = "--ios" ] ; then
|
|
|
85
85
|
|
|
86
86
|
IOS_TARGET="$2"
|
|
87
87
|
IOS_VER="$3"
|
|
88
|
+
IOS_ARCH="$4"
|
|
88
89
|
|
|
89
90
|
if [ -z "$IOS_VER" ]; then
|
|
90
91
|
IOS_VER="13.0"
|
|
91
92
|
fi
|
|
92
93
|
|
|
94
|
+
if [ -z "$IOS_ARCH" ]; then
|
|
95
|
+
IOS_ARCH="arm64"
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
# Replace spaces with semicolons for CMake list
|
|
99
|
+
IOS_ARCH=$(echo "$IOS_ARCH" | tr ' ' ';')
|
|
100
|
+
|
|
93
101
|
SYSROOT="iphoneos"
|
|
94
102
|
if echo "$IOS_TARGET" | grep -q "simulator"; then
|
|
95
103
|
SYSROOT="iphonesimulator"
|
|
@@ -100,7 +108,7 @@ elif [ "$1" = "--ios" ] ; then
|
|
|
100
108
|
cmake -DCMAKE_SYSTEM_NAME=iOS \
|
|
101
109
|
-DLIBSWORD_LIBRARY_TYPE=Static \
|
|
102
110
|
-DCMAKE_CXX_STANDARD=11 \
|
|
103
|
-
-DCMAKE_OSX_ARCHITECTURES="
|
|
111
|
+
-DCMAKE_OSX_ARCHITECTURES="$IOS_ARCH" \
|
|
104
112
|
-DCMAKE_OSX_SYSROOT=$SYSROOT \
|
|
105
113
|
-DCMAKE_OSX_DEPLOYMENT_TARGET=$IOS_VER \
|
|
106
114
|
-DCMAKE_BUILD_TYPE=$SWORD_BUILD_TYPE \
|
|
@@ -39,6 +39,11 @@
|
|
|
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
|
+
|
|
42
47
|
using namespace std;
|
|
43
48
|
using namespace sword;
|
|
44
49
|
|
|
@@ -117,7 +122,9 @@ Napi::Object NodeSwordInterface::Init(Napi::Env env, Napi::Object exports)
|
|
|
117
122
|
InstanceMethod("getSwordTranslation", &NodeSwordInterface::getSwordTranslation),
|
|
118
123
|
InstanceMethod("getBookAbbreviation", &NodeSwordInterface::getBookAbbreviation),
|
|
119
124
|
InstanceMethod("getSwordVersion", &NodeSwordInterface::getSwordVersion),
|
|
120
|
-
InstanceMethod("getSwordPath", &NodeSwordInterface::getSwordPath)
|
|
125
|
+
InstanceMethod("getSwordPath", &NodeSwordInterface::getSwordPath),
|
|
126
|
+
InstanceMethod("unTarGZ", &NodeSwordInterface::unTarGZ),
|
|
127
|
+
InstanceMethod("unZip", &NodeSwordInterface::unZip)
|
|
121
128
|
});
|
|
122
129
|
|
|
123
130
|
constructor = Napi::Persistent(func);
|
|
@@ -1024,3 +1031,88 @@ Napi::Value NodeSwordInterface::getSwordPath(const Napi::CallbackInfo& info)
|
|
|
1024
1031
|
unlockApi();
|
|
1025
1032
|
return swordPath;
|
|
1026
1033
|
}
|
|
1034
|
+
|
|
1035
|
+
Napi::Value NodeSwordInterface::unTarGZ(const Napi::CallbackInfo& info)
|
|
1036
|
+
{
|
|
1037
|
+
Napi::Env env = info.Env();
|
|
1038
|
+
INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::string);
|
|
1039
|
+
lockApi();
|
|
1040
|
+
|
|
1041
|
+
string filePath = info[0].As<Napi::String>().Utf8Value();
|
|
1042
|
+
string destPath = info[1].As<Napi::String>().Utf8Value();
|
|
1043
|
+
|
|
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);
|
|
1052
|
+
|
|
1053
|
+
unlockApi();
|
|
1054
|
+
return Napi::Boolean::New(env, ret == 0);
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
Napi::Value NodeSwordInterface::unZip(const Napi::CallbackInfo& info)
|
|
1058
|
+
{
|
|
1059
|
+
Napi::Env env = info.Env();
|
|
1060
|
+
INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::string);
|
|
1061
|
+
lockApi();
|
|
1062
|
+
|
|
1063
|
+
string filePath = info[0].As<Napi::String>().Utf8Value();
|
|
1064
|
+
string destPath = info[1].As<Napi::String>().Utf8Value();
|
|
1065
|
+
|
|
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);
|
|
1115
|
+
|
|
1116
|
+
unlockApi();
|
|
1117
|
+
return Napi::Boolean::New(env, true);
|
|
1118
|
+
}
|
|
@@ -102,6 +102,8 @@ private:
|
|
|
102
102
|
Napi::Value getBookAbbreviation(const Napi::CallbackInfo& info);
|
|
103
103
|
Napi::Value getSwordVersion(const Napi::CallbackInfo& info);
|
|
104
104
|
Napi::Value getSwordPath(const Napi::CallbackInfo& info);
|
|
105
|
+
Napi::Value unTarGZ(const Napi::CallbackInfo& info);
|
|
106
|
+
Napi::Value unZip(const Napi::CallbackInfo& info);
|
|
105
107
|
|
|
106
108
|
int validateParams(const Napi::CallbackInfo& info, std::vector<ParamType> paramSpec);
|
|
107
109
|
ModuleType getModuleTypeFromString(std::string moduleTypeString);
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
|
2
|
+
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
|
3
|
+
|
|
4
|
+
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
|
5
|
+
|
|
6
|
+
Modifications for Zip64 support
|
|
7
|
+
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
|
8
|
+
|
|
9
|
+
For more info read MiniZip_info.txt
|
|
10
|
+
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
|
|
14
|
+
#define _CRT_SECURE_NO_WARNINGS
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
#if defined(__APPLE__) || defined(IOAPI_NO_64)
|
|
18
|
+
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
|
|
19
|
+
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
|
|
20
|
+
#define FTELLO_FUNC(stream) ftello(stream)
|
|
21
|
+
#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
|
|
22
|
+
#else
|
|
23
|
+
#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
|
|
24
|
+
#define FTELLO_FUNC(stream) ftello64(stream)
|
|
25
|
+
#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
#include "ioapi.h"
|
|
30
|
+
|
|
31
|
+
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
|
|
32
|
+
{
|
|
33
|
+
if (pfilefunc->zfile_func64.zopen64_file != NULL)
|
|
34
|
+
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
|
|
35
|
+
else
|
|
36
|
+
{
|
|
37
|
+
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
|
|
42
|
+
{
|
|
43
|
+
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
|
44
|
+
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
|
|
45
|
+
else
|
|
46
|
+
{
|
|
47
|
+
uLong offsetTruncated = (uLong)offset;
|
|
48
|
+
if (offsetTruncated != offset)
|
|
49
|
+
return -1;
|
|
50
|
+
else
|
|
51
|
+
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
|
|
56
|
+
{
|
|
57
|
+
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
|
58
|
+
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
|
|
59
|
+
else
|
|
60
|
+
{
|
|
61
|
+
uLong tell_uLong = (uLong)(*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
|
|
62
|
+
if ((tell_uLong) == MAXU32)
|
|
63
|
+
return (ZPOS64_T)-1;
|
|
64
|
+
else
|
|
65
|
+
return tell_uLong;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
|
|
70
|
+
{
|
|
71
|
+
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
|
|
72
|
+
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
|
|
73
|
+
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
|
74
|
+
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
|
|
75
|
+
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
|
|
76
|
+
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
|
|
77
|
+
p_filefunc64_32->zfile_func64.zseek64_file = NULL;
|
|
78
|
+
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
|
|
79
|
+
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
|
80
|
+
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
|
|
81
|
+
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
|
|
82
|
+
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
|
|
88
|
+
static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
|
89
|
+
static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
|
|
90
|
+
static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
|
|
91
|
+
static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
|
|
92
|
+
static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
|
|
93
|
+
static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
|
|
94
|
+
|
|
95
|
+
static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
|
|
96
|
+
{
|
|
97
|
+
(void)opaque;
|
|
98
|
+
FILE* file = NULL;
|
|
99
|
+
const char* mode_fopen = NULL;
|
|
100
|
+
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
|
101
|
+
mode_fopen = "rb";
|
|
102
|
+
else
|
|
103
|
+
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
|
104
|
+
mode_fopen = "r+b";
|
|
105
|
+
else
|
|
106
|
+
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
|
107
|
+
mode_fopen = "wb";
|
|
108
|
+
|
|
109
|
+
if ((filename!=NULL) && (mode_fopen != NULL))
|
|
110
|
+
file = fopen(filename, mode_fopen);
|
|
111
|
+
return file;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
|
|
115
|
+
{
|
|
116
|
+
(void)opaque;
|
|
117
|
+
FILE* file = NULL;
|
|
118
|
+
const char* mode_fopen = NULL;
|
|
119
|
+
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
|
120
|
+
mode_fopen = "rb";
|
|
121
|
+
else
|
|
122
|
+
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
|
123
|
+
mode_fopen = "r+b";
|
|
124
|
+
else
|
|
125
|
+
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
|
126
|
+
mode_fopen = "wb";
|
|
127
|
+
|
|
128
|
+
if ((filename!=NULL) && (mode_fopen != NULL))
|
|
129
|
+
file = FOPEN_FUNC((const char*)filename, mode_fopen);
|
|
130
|
+
return file;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
|
|
135
|
+
{
|
|
136
|
+
(void)opaque;
|
|
137
|
+
uLong ret;
|
|
138
|
+
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
|
|
139
|
+
return ret;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
|
|
143
|
+
{
|
|
144
|
+
(void)opaque;
|
|
145
|
+
uLong ret;
|
|
146
|
+
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
|
|
147
|
+
return ret;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
|
|
151
|
+
{
|
|
152
|
+
(void)opaque;
|
|
153
|
+
long ret;
|
|
154
|
+
ret = ftell((FILE *)stream);
|
|
155
|
+
return ret;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
|
|
160
|
+
{
|
|
161
|
+
(void)opaque;
|
|
162
|
+
ZPOS64_T ret;
|
|
163
|
+
ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream);
|
|
164
|
+
return ret;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
|
|
168
|
+
{
|
|
169
|
+
(void)opaque;
|
|
170
|
+
int fseek_origin=0;
|
|
171
|
+
long ret;
|
|
172
|
+
switch (origin)
|
|
173
|
+
{
|
|
174
|
+
case ZLIB_FILEFUNC_SEEK_CUR :
|
|
175
|
+
fseek_origin = SEEK_CUR;
|
|
176
|
+
break;
|
|
177
|
+
case ZLIB_FILEFUNC_SEEK_END :
|
|
178
|
+
fseek_origin = SEEK_END;
|
|
179
|
+
break;
|
|
180
|
+
case ZLIB_FILEFUNC_SEEK_SET :
|
|
181
|
+
fseek_origin = SEEK_SET;
|
|
182
|
+
break;
|
|
183
|
+
default: return -1;
|
|
184
|
+
}
|
|
185
|
+
ret = 0;
|
|
186
|
+
if (fseek((FILE *)stream, (long)offset, fseek_origin) != 0)
|
|
187
|
+
ret = -1;
|
|
188
|
+
return ret;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
|
|
192
|
+
{
|
|
193
|
+
(void)opaque;
|
|
194
|
+
int fseek_origin=0;
|
|
195
|
+
long ret;
|
|
196
|
+
switch (origin)
|
|
197
|
+
{
|
|
198
|
+
case ZLIB_FILEFUNC_SEEK_CUR :
|
|
199
|
+
fseek_origin = SEEK_CUR;
|
|
200
|
+
break;
|
|
201
|
+
case ZLIB_FILEFUNC_SEEK_END :
|
|
202
|
+
fseek_origin = SEEK_END;
|
|
203
|
+
break;
|
|
204
|
+
case ZLIB_FILEFUNC_SEEK_SET :
|
|
205
|
+
fseek_origin = SEEK_SET;
|
|
206
|
+
break;
|
|
207
|
+
default: return -1;
|
|
208
|
+
}
|
|
209
|
+
ret = 0;
|
|
210
|
+
|
|
211
|
+
if(FSEEKO_FUNC((FILE *)stream, (long)offset, fseek_origin) != 0)
|
|
212
|
+
ret = -1;
|
|
213
|
+
|
|
214
|
+
return ret;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
|
|
219
|
+
{
|
|
220
|
+
(void)opaque;
|
|
221
|
+
int ret;
|
|
222
|
+
ret = fclose((FILE *)stream);
|
|
223
|
+
return ret;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
|
|
227
|
+
{
|
|
228
|
+
(void)opaque;
|
|
229
|
+
int ret;
|
|
230
|
+
ret = ferror((FILE *)stream);
|
|
231
|
+
return ret;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
void fill_fopen_filefunc (pzlib_filefunc_def)
|
|
235
|
+
zlib_filefunc_def* pzlib_filefunc_def;
|
|
236
|
+
{
|
|
237
|
+
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
|
238
|
+
pzlib_filefunc_def->zread_file = fread_file_func;
|
|
239
|
+
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
|
240
|
+
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
|
241
|
+
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
|
242
|
+
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
|
243
|
+
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
|
244
|
+
pzlib_filefunc_def->opaque = NULL;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
|
|
248
|
+
{
|
|
249
|
+
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
|
|
250
|
+
pzlib_filefunc_def->zread_file = fread_file_func;
|
|
251
|
+
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
|
252
|
+
pzlib_filefunc_def->ztell64_file = ftell64_file_func;
|
|
253
|
+
pzlib_filefunc_def->zseek64_file = fseek64_file_func;
|
|
254
|
+
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
|
255
|
+
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
|
256
|
+
pzlib_filefunc_def->opaque = NULL;
|
|
257
|
+
}
|