koffi 2.12.1 → 2.12.3
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/CHANGELOG.md +21 -0
- package/LICENSE.txt +2 -2
- package/README.md +8 -8
- package/build/koffi/darwin_arm64/koffi.node +0 -0
- package/build/koffi/darwin_x64/koffi.node +0 -0
- package/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/build/koffi/freebsd_x64/koffi.node +0 -0
- package/build/koffi/linux_arm64/koffi.node +0 -0
- package/build/koffi/linux_armhf/koffi.node +0 -0
- package/build/koffi/linux_ia32/koffi.node +0 -0
- package/build/koffi/linux_loong64/koffi.node +0 -0
- package/build/koffi/linux_riscv64d/koffi.node +0 -0
- package/build/koffi/linux_x64/koffi.node +0 -0
- package/build/koffi/musl_arm64/koffi.node +0 -0
- package/build/koffi/musl_x64/koffi.node +0 -0
- package/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/build/koffi/openbsd_x64/koffi.node +0 -0
- package/build/koffi/win32_arm64/koffi.exp +0 -0
- package/build/koffi/win32_arm64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.exp +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.exp +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/doc/assets.ini +3 -3
- package/doc/develop.sh +4 -3
- package/doc/pages/platforms.md +1 -1
- package/doc/static/highlight.js +1 -1
- package/doc/static/koffi.css +3 -2
- package/doc/static/print.css +1 -1
- package/doc/templates/code.html +5 -5
- package/doc/templates/page.html +4 -4
- package/index.d.ts +228 -145
- package/index.js +25 -25
- package/indirect.js +25 -5
- package/package.json +2 -2
- package/src/cnoke/LICENSE.txt +2 -2
- package/src/cnoke/README.md +2 -0
- package/src/cnoke/assets/FindCNoke.cmake +12 -2
- package/src/cnoke/assets/win_delay_hook.c +4 -4
- package/src/cnoke/cnoke.js +4 -2
- package/src/cnoke/package.json +1 -1
- package/src/cnoke/src/builder.js +11 -14
- package/src/cnoke/src/index.js +2 -2
- package/src/cnoke/src/tools.js +34 -2
- package/src/core/{libcc/libcc.cc → base/base.cc} +3174 -1640
- package/src/core/{libcc/libcc.hh → base/base.hh} +3066 -2427
- package/src/core/{libcc → base}/mimetypes.inc +42 -4
- package/src/core/{libcc → base}/mimetypes_gen.py +3 -3
- package/src/core/base/unicode.inc +426 -0
- package/src/core/base/unicode_gen.py +189 -0
- package/src/koffi/CMakeLists.txt +7 -5
- package/src/koffi/cmake/raylib.cmake +6 -2
- package/src/koffi/cmake/{sqlite.cmake → sqlite3.cmake} +3 -3
- package/src/koffi/examples/electron-forge/forge.config.js +23 -3
- package/src/koffi/examples/electron-forge/package.json +18 -16
- package/src/koffi/src/abi_arm32.cc +7 -7
- package/src/koffi/src/abi_arm32_asm.S +2 -2
- package/src/koffi/src/abi_arm64.cc +45 -45
- package/src/koffi/src/abi_arm64_asm.S +4 -4
- package/src/koffi/src/abi_arm64_asm.asm +2 -2
- package/src/koffi/src/abi_loong64_asm.S +2 -2
- package/src/koffi/src/abi_riscv64.cc +5 -5
- package/src/koffi/src/abi_riscv64_asm.S +2 -2
- package/src/koffi/src/abi_x64_sysv.cc +3 -3
- package/src/koffi/src/abi_x64_sysv_asm.S +5 -5
- package/src/koffi/src/abi_x64_win.cc +3 -3
- package/src/koffi/src/abi_x64_win_asm.asm +2 -2
- package/src/koffi/src/abi_x86.cc +8 -8
- package/src/koffi/src/abi_x86_asm.S +2 -2
- package/src/koffi/src/abi_x86_asm.asm +2 -2
- package/src/koffi/src/call.cc +12 -12
- package/src/koffi/src/call.hh +8 -8
- package/src/koffi/src/errno.inc +152 -152
- package/src/koffi/src/ffi.cc +44 -39
- package/src/koffi/src/ffi.hh +6 -6
- package/src/koffi/src/init.js +1 -1
- package/src/koffi/src/parser.cc +5 -5
- package/src/koffi/src/parser.hh +3 -3
- package/src/koffi/src/trampolines/armasm.inc +2 -2
- package/src/koffi/src/trampolines/gnu.inc +2 -2
- package/src/koffi/src/trampolines/masm32.inc +2 -2
- package/src/koffi/src/trampolines/masm64.inc +2 -2
- package/src/koffi/src/trampolines/prototypes.inc +2 -2
- package/src/koffi/src/util.cc +9 -9
- package/src/koffi/src/util.hh +3 -3
- package/src/koffi/src/win32.cc +5 -5
- package/src/koffi/src/win32.hh +9 -9
- package/vendor/node-addon-api/CHANGELOG.md +97 -2
- package/vendor/node-addon-api/CONTRIBUTING.md +117 -7
- package/vendor/node-addon-api/README.md +25 -249
- package/vendor/node-addon-api/common.gypi +1 -0
- package/vendor/node-addon-api/doc/README.md +145 -0
- package/vendor/node-addon-api/doc/array_buffer.md +15 -15
- package/vendor/node-addon-api/doc/basic_env.md +200 -0
- package/vendor/node-addon-api/doc/buffer.md +24 -26
- package/vendor/node-addon-api/doc/cmake-js.md +19 -0
- package/vendor/node-addon-api/doc/{creating_a_release.md → contributing/creating_a_release.md} +16 -4
- package/vendor/node-addon-api/doc/env.md +11 -131
- package/vendor/node-addon-api/doc/error_handling.md +12 -0
- package/vendor/node-addon-api/doc/external.md +13 -4
- package/vendor/node-addon-api/doc/finalization.md +153 -0
- package/vendor/node-addon-api/doc/memory_management.md +1 -1
- package/vendor/node-addon-api/doc/object_wrap.md +19 -3
- package/vendor/node-addon-api/doc/promises.md +51 -0
- package/vendor/node-addon-api/doc/setup.md +29 -6
- package/vendor/node-addon-api/doc/value.md +13 -0
- package/vendor/node-addon-api/doc/version_management.md +2 -2
- package/vendor/node-addon-api/eslint.config.js +5 -0
- package/vendor/node-addon-api/index.js +2 -0
- package/vendor/node-addon-api/napi-inl.h +592 -166
- package/vendor/node-addon-api/napi.h +167 -59
- package/vendor/node-addon-api/node_addon_api.gyp +10 -0
- package/vendor/node-addon-api/noexcept.gypi +1 -1
- package/vendor/node-addon-api/package.json +10 -13
- package/vendor/node-addon-api/release-please-config.json +15 -0
- package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +2 -1
- package/vendor/node-addon-api/test/array_buffer.js +1 -1
- package/vendor/node-addon-api/test/async_context.js +2 -2
- package/vendor/node-addon-api/test/async_progress_queue_worker.js +3 -3
- package/vendor/node-addon-api/test/async_progress_worker.js +3 -3
- package/vendor/node-addon-api/test/async_worker.cc +15 -13
- package/vendor/node-addon-api/test/async_worker.js +5 -5
- package/vendor/node-addon-api/test/basic_types/value.cc +6 -0
- package/vendor/node-addon-api/test/basic_types/value.js +17 -0
- package/vendor/node-addon-api/test/binding.cc +8 -0
- package/vendor/node-addon-api/test/binding.gyp +23 -1
- package/vendor/node-addon-api/test/buffer.js +1 -2
- package/vendor/node-addon-api/test/common/index.js +1 -1
- package/vendor/node-addon-api/test/except_all.cc +22 -0
- package/vendor/node-addon-api/test/except_all.js +14 -0
- package/vendor/node-addon-api/test/exports.js +19 -0
- package/vendor/node-addon-api/test/finalizer_order.cc +152 -0
- package/vendor/node-addon-api/test/finalizer_order.js +98 -0
- package/vendor/node-addon-api/test/function.js +2 -2
- package/vendor/node-addon-api/test/function_reference.js +2 -2
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +4 -4
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +4 -4
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +3 -3
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +5 -5
- package/vendor/node-addon-api/test/name.cc +10 -8
- package/vendor/node-addon-api/test/object/delete_property.cc +5 -5
- package/vendor/node-addon-api/test/object/get_property.cc +5 -5
- package/vendor/node-addon-api/test/object/has_own_property.cc +4 -4
- package/vendor/node-addon-api/test/object/has_property.cc +5 -5
- package/vendor/node-addon-api/test/object/object.cc +1 -1
- package/vendor/node-addon-api/test/object/set_property.cc +5 -5
- package/vendor/node-addon-api/test/object/subscript_operator.cc +3 -3
- package/vendor/node-addon-api/test/object_reference.cc +18 -18
- package/vendor/node-addon-api/test/promise.cc +75 -0
- package/vendor/node-addon-api/test/promise.js +23 -0
- package/vendor/node-addon-api/test/require_basic_finalizers/index.js +38 -0
- package/vendor/node-addon-api/test/require_basic_finalizers/tpl/addon.cc +12 -0
- package/vendor/node-addon-api/test/require_basic_finalizers/tpl/binding.gyp +48 -0
- package/vendor/node-addon-api/test/require_basic_finalizers/tpl/index.js +3 -0
- package/vendor/node-addon-api/test/require_basic_finalizers/tpl/package.json +11 -0
- package/vendor/node-addon-api/test/run_script.cc +1 -1
- package/vendor/node-addon-api/test/type_taggable.cc +1 -1
- package/vendor/node-addon-api/test/type_taggable.js +3 -4
- package/vendor/node-addon-api/test/typedarray.cc +28 -24
- package/vendor/node-addon-api/tools/conversion.js +1 -1
- package/vendor/node-api-headers/CHANGELOG.md +29 -0
- package/vendor/node-api-headers/CREATING_A_RELEASE.md +12 -2
- package/vendor/node-api-headers/def/js_native_api.def +6 -1
- package/vendor/node-api-headers/def/node_api.def +7 -1
- package/vendor/node-api-headers/include/js_native_api.h +56 -24
- package/vendor/node-api-headers/include/js_native_api_types.h +27 -0
- package/vendor/node-api-headers/include/node_api.h +38 -29
- package/vendor/node-api-headers/lib/parse-utils.js +92 -0
- package/vendor/node-api-headers/package.json +7 -7
- package/vendor/node-api-headers/release-please-config.json +12 -0
- package/vendor/node-api-headers/scripts/update-headers.js +63 -12
- package/vendor/node-api-headers/scripts/write-symbols.js +1 -1
- package/vendor/node-api-headers/symbols.js +17 -1
- package/vendor/node-api-headers/test/parse-utils.js +21 -0
- package/doc/flat/flat.css +0 -27
- package/doc/flat/normal.css +0 -429
- package/doc/flat/print.css +0 -29
- package/doc/flat/reset.css +0 -41
- package/doc/flat/small.css +0 -104
- package/doc/flat/static.js +0 -161
- package/src/core/libcc/brotli.cc +0 -186
- package/src/core/libcc/lz4.cc +0 -197
- package/src/core/libcc/miniz.cc +0 -353
- package/vendor/node-addon-api/tools/eslint-format.js +0 -79
- /package/vendor/node-api-headers/{scripts → lib}/clang-utils.js +0 -0
package/src/core/libcc/miniz.cc
DELETED
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
|
|
2
|
-
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
-
// this software and associated documentation files (the “Software”), to deal in
|
|
5
|
-
// the Software without restriction, including without limitation the rights to use,
|
|
6
|
-
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
7
|
-
// Software, and to permit persons to whom the Software is furnished to do so,
|
|
8
|
-
// subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
11
|
-
// copies or substantial portions of the Software.
|
|
12
|
-
|
|
13
|
-
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
|
14
|
-
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
15
|
-
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
16
|
-
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
17
|
-
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
18
|
-
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
19
|
-
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
20
|
-
// OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
-
|
|
22
|
-
#include "libcc.hh"
|
|
23
|
-
|
|
24
|
-
#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
|
|
25
|
-
#include "vendor/miniz/miniz.h"
|
|
26
|
-
|
|
27
|
-
namespace RG {
|
|
28
|
-
|
|
29
|
-
class MinizDecompressor: public StreamDecoder {
|
|
30
|
-
tinfl_decompressor inflator;
|
|
31
|
-
bool done = false;
|
|
32
|
-
|
|
33
|
-
uint8_t in_buf[256 * 1024];
|
|
34
|
-
uint8_t *in_ptr = nullptr;
|
|
35
|
-
Size in_len = 0;
|
|
36
|
-
|
|
37
|
-
uint8_t out_buf[256 * 1024];
|
|
38
|
-
uint8_t *out_ptr = nullptr;
|
|
39
|
-
Size out_len = 0;
|
|
40
|
-
|
|
41
|
-
// Gzip support
|
|
42
|
-
bool is_gzip = false;
|
|
43
|
-
bool header_done = false;
|
|
44
|
-
uint32_t crc32 = MZ_CRC32_INIT;
|
|
45
|
-
Size uncompressed_size = 0;
|
|
46
|
-
|
|
47
|
-
public:
|
|
48
|
-
MinizDecompressor(StreamReader *reader, CompressionType type);
|
|
49
|
-
~MinizDecompressor() {}
|
|
50
|
-
|
|
51
|
-
Size Read(Size max_len, void *out_buf) override;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
MinizDecompressor::MinizDecompressor(StreamReader *reader, CompressionType type)
|
|
55
|
-
: StreamDecoder(reader)
|
|
56
|
-
{
|
|
57
|
-
static_assert(RG_SIZE(out_buf) >= TINFL_LZ_DICT_SIZE);
|
|
58
|
-
|
|
59
|
-
tinfl_init(&inflator);
|
|
60
|
-
is_gzip = (type == CompressionType::Gzip);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
Size MinizDecompressor::Read(Size max_len, void *user_buf)
|
|
64
|
-
{
|
|
65
|
-
// Gzip header is not directly supported by miniz. Currently this
|
|
66
|
-
// will fail if the header is longer than 4096 bytes, which is
|
|
67
|
-
// probably quite rare.
|
|
68
|
-
if (is_gzip && !header_done) {
|
|
69
|
-
uint8_t header[4096];
|
|
70
|
-
Size header_len;
|
|
71
|
-
|
|
72
|
-
header_len = ReadRaw(RG_SIZE(header), header);
|
|
73
|
-
if (header_len < 0) {
|
|
74
|
-
return -1;
|
|
75
|
-
} else if (header_len < 10 || header[0] != 0x1F || header[1] != 0x8B) {
|
|
76
|
-
LogError("File '%1' does not look like a Gzip stream", GetFileName());
|
|
77
|
-
return -1;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
Size header_offset = 10;
|
|
81
|
-
if (header[3] & 0x4) { // FEXTRA
|
|
82
|
-
if (header_len - header_offset < 2)
|
|
83
|
-
goto truncated_error;
|
|
84
|
-
uint16_t extra_len = (uint16_t)((header[11] << 8) | header[10]);
|
|
85
|
-
if (extra_len > header_len - header_offset)
|
|
86
|
-
goto truncated_error;
|
|
87
|
-
header_offset += extra_len;
|
|
88
|
-
}
|
|
89
|
-
if (header[3] & 0x8) { // FNAME
|
|
90
|
-
uint8_t *end_ptr = (uint8_t *)memchr(header + header_offset, '\0',
|
|
91
|
-
(size_t)(header_len - header_offset));
|
|
92
|
-
if (!end_ptr)
|
|
93
|
-
goto truncated_error;
|
|
94
|
-
header_offset = end_ptr - header + 1;
|
|
95
|
-
}
|
|
96
|
-
if (header[3] & 0x10) { // FCOMMENT
|
|
97
|
-
uint8_t *end_ptr = (uint8_t *)memchr(header + header_offset, '\0',
|
|
98
|
-
(size_t)(header_len - header_offset));
|
|
99
|
-
if (!end_ptr)
|
|
100
|
-
goto truncated_error;
|
|
101
|
-
header_offset = end_ptr - header + 1;
|
|
102
|
-
}
|
|
103
|
-
if (header[3] & 0x2) { // FHCRC
|
|
104
|
-
if (header_len - header_offset < 2)
|
|
105
|
-
goto truncated_error;
|
|
106
|
-
uint16_t crc16 = (uint16_t)(header[1] << 8 | header[0]);
|
|
107
|
-
if ((mz_crc32(MZ_CRC32_INIT, header, (size_t)header_offset) & 0xFFFF) == crc16) {
|
|
108
|
-
LogError("Failed header CRC16 check in '%s'", GetFileName());
|
|
109
|
-
return -1;
|
|
110
|
-
}
|
|
111
|
-
header_offset += 2;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Put back remaining data in the buffer
|
|
115
|
-
memcpy_safe(in_buf, header + header_offset, (size_t)(header_len - header_offset));
|
|
116
|
-
in_ptr = in_buf;
|
|
117
|
-
in_len = header_len - header_offset;
|
|
118
|
-
|
|
119
|
-
header_done = true;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Inflate (with miniz)
|
|
123
|
-
{
|
|
124
|
-
Size read_len = 0;
|
|
125
|
-
for (;;) {
|
|
126
|
-
if (max_len < out_len) {
|
|
127
|
-
memcpy_safe(user_buf, out_ptr, (size_t)max_len);
|
|
128
|
-
read_len += max_len;
|
|
129
|
-
out_ptr += max_len;
|
|
130
|
-
out_len -= max_len;
|
|
131
|
-
|
|
132
|
-
return read_len;
|
|
133
|
-
} else {
|
|
134
|
-
memcpy_safe(user_buf, out_ptr, (size_t)out_len);
|
|
135
|
-
read_len += out_len;
|
|
136
|
-
user_buf = (uint8_t *)user_buf + out_len;
|
|
137
|
-
max_len -= out_len;
|
|
138
|
-
out_ptr = out_buf;
|
|
139
|
-
out_len = 0;
|
|
140
|
-
|
|
141
|
-
if (done) {
|
|
142
|
-
SetEOF(true);
|
|
143
|
-
return read_len;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
while (out_len < RG_SIZE(out_buf)) {
|
|
148
|
-
if (!in_len) {
|
|
149
|
-
in_ptr = in_buf;
|
|
150
|
-
in_len = ReadRaw(RG_SIZE(in_buf), in_buf);
|
|
151
|
-
if (in_len < 0)
|
|
152
|
-
return read_len ? read_len : in_len;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
size_t in_arg = (size_t)in_len;
|
|
156
|
-
size_t out_arg = (size_t)(RG_SIZE(out_buf) - out_len);
|
|
157
|
-
uint32_t flags = (uint32_t)
|
|
158
|
-
((is_gzip ? 0 : TINFL_FLAG_PARSE_ZLIB_HEADER) |
|
|
159
|
-
(IsSourceEOF() ? 0 : TINFL_FLAG_HAS_MORE_INPUT));
|
|
160
|
-
|
|
161
|
-
tinfl_status status = tinfl_decompress(&inflator, in_ptr, &in_arg,
|
|
162
|
-
out_buf, out_buf + out_len,
|
|
163
|
-
&out_arg, flags);
|
|
164
|
-
|
|
165
|
-
if (is_gzip) {
|
|
166
|
-
crc32 = (uint32_t)mz_crc32(crc32, out_buf + out_len, out_arg);
|
|
167
|
-
uncompressed_size += (Size)out_arg;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
in_ptr += (Size)in_arg;
|
|
171
|
-
in_len -= (Size)in_arg;
|
|
172
|
-
out_len += (Size)out_arg;
|
|
173
|
-
|
|
174
|
-
if (status == TINFL_STATUS_DONE) {
|
|
175
|
-
// Gzip footer (CRC and size check)
|
|
176
|
-
if (is_gzip) {
|
|
177
|
-
uint32_t footer[2];
|
|
178
|
-
static_assert(RG_SIZE(footer) == 8);
|
|
179
|
-
|
|
180
|
-
if (in_len < RG_SIZE(footer)) {
|
|
181
|
-
memcpy_safe(footer, in_ptr, (size_t)in_len);
|
|
182
|
-
|
|
183
|
-
Size missing_len = RG_SIZE(footer) - in_len;
|
|
184
|
-
if (ReadRaw(missing_len, footer + in_len) < missing_len) {
|
|
185
|
-
if (IsValid()) {
|
|
186
|
-
goto truncated_error;
|
|
187
|
-
} else {
|
|
188
|
-
return -1;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
} else {
|
|
192
|
-
memcpy_safe(footer, in_ptr, RG_SIZE(footer));
|
|
193
|
-
}
|
|
194
|
-
footer[0] = LittleEndian(footer[0]);
|
|
195
|
-
footer[1] = LittleEndian(footer[1]);
|
|
196
|
-
|
|
197
|
-
if (crc32 != footer[0] || (uint32_t)uncompressed_size != footer[1]) {
|
|
198
|
-
LogError("Failed CRC32 or size check in GZip stream '%1'", GetFileName());
|
|
199
|
-
return -1;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
done = true;
|
|
204
|
-
break;
|
|
205
|
-
} else if (status < TINFL_STATUS_DONE) {
|
|
206
|
-
LogError("Failed to decompress '%1' (Deflate)", GetFileName());
|
|
207
|
-
return -1;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
truncated_error:
|
|
214
|
-
LogError("Truncated Gzip header in '%1'", GetFileName());
|
|
215
|
-
return -1;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
class MinizCompressor: public StreamEncoder {
|
|
219
|
-
tdefl_compressor deflator;
|
|
220
|
-
|
|
221
|
-
// Gzip support
|
|
222
|
-
bool is_gzip = false;
|
|
223
|
-
uint32_t crc32 = MZ_CRC32_INIT;
|
|
224
|
-
Size uncompressed_size = 0;
|
|
225
|
-
|
|
226
|
-
// Used to buffer small writes
|
|
227
|
-
LocalArray<uint8_t, 1024> small_buf;
|
|
228
|
-
|
|
229
|
-
public:
|
|
230
|
-
MinizCompressor(StreamWriter *writer, CompressionType type, CompressionSpeed speed);
|
|
231
|
-
~MinizCompressor() {}
|
|
232
|
-
|
|
233
|
-
bool Write(Span<const uint8_t> buf) override;
|
|
234
|
-
bool Finalize() override;
|
|
235
|
-
|
|
236
|
-
private:
|
|
237
|
-
bool WriteDeflate(Span<const uint8_t> buf);
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
MinizCompressor::MinizCompressor(StreamWriter *writer, CompressionType type, CompressionSpeed speed)
|
|
241
|
-
: StreamEncoder(writer)
|
|
242
|
-
{
|
|
243
|
-
is_gzip = (type == CompressionType::Gzip);
|
|
244
|
-
|
|
245
|
-
int flags = 0;
|
|
246
|
-
switch (speed) {
|
|
247
|
-
case CompressionSpeed::Default: { flags = 32 | TDEFL_GREEDY_PARSING_FLAG; } break;
|
|
248
|
-
case CompressionSpeed::Slow: { flags = 512; } break;
|
|
249
|
-
case CompressionSpeed::Fast: { flags = 1 | TDEFL_GREEDY_PARSING_FLAG; } break;
|
|
250
|
-
}
|
|
251
|
-
flags |= (is_gzip ? 0 : TDEFL_WRITE_ZLIB_HEADER);
|
|
252
|
-
|
|
253
|
-
tdefl_status status = tdefl_init(&deflator, [](const void *buf, int len, void *udata) {
|
|
254
|
-
MinizCompressor *compressor = (MinizCompressor *)udata;
|
|
255
|
-
return (int)compressor->WriteRaw(MakeSpan((uint8_t *)buf, len));
|
|
256
|
-
}, this, flags);
|
|
257
|
-
RG_ASSERT(status == TDEFL_STATUS_OKAY);
|
|
258
|
-
|
|
259
|
-
if (is_gzip) {
|
|
260
|
-
static uint8_t gzip_header[] = {
|
|
261
|
-
0x1F, 0x8B, // Fixed bytes
|
|
262
|
-
8, // Deflate
|
|
263
|
-
0, // FLG
|
|
264
|
-
0, 0, 0, 0, // MTIME
|
|
265
|
-
0, // XFL
|
|
266
|
-
0 // OS
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
WriteRaw(gzip_header);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
bool MinizCompressor::Write(Span<const uint8_t> buf)
|
|
274
|
-
{
|
|
275
|
-
if (small_buf.len) {
|
|
276
|
-
Size copy_len = std::min(buf.len, small_buf.Available());
|
|
277
|
-
|
|
278
|
-
memcpy_safe(small_buf.end(), buf.ptr, copy_len);
|
|
279
|
-
small_buf.len += copy_len;
|
|
280
|
-
buf.ptr += copy_len;
|
|
281
|
-
buf.len -= copy_len;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (buf.len) {
|
|
285
|
-
if (small_buf.len && !WriteDeflate(small_buf))
|
|
286
|
-
return false;
|
|
287
|
-
small_buf.Clear();
|
|
288
|
-
|
|
289
|
-
if (buf.len >= RG_SIZE(small_buf.data) / 2) {
|
|
290
|
-
if (!WriteDeflate(buf))
|
|
291
|
-
return false;
|
|
292
|
-
} else {
|
|
293
|
-
memcpy_safe(small_buf.data, buf.ptr, buf.len);
|
|
294
|
-
small_buf.len = buf.len;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return true;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
bool MinizCompressor::WriteDeflate(Span<const uint8_t> buf)
|
|
302
|
-
{
|
|
303
|
-
if (is_gzip) {
|
|
304
|
-
crc32 = (uint32_t)mz_crc32(crc32, buf.ptr, (size_t)buf.len);
|
|
305
|
-
uncompressed_size += buf.len;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
tdefl_status status = tdefl_compress_buffer(&deflator, buf.ptr, (size_t)buf.len, TDEFL_NO_FLUSH);
|
|
309
|
-
if (status < TDEFL_STATUS_OKAY) {
|
|
310
|
-
if (status != TDEFL_STATUS_PUT_BUF_FAILED) {
|
|
311
|
-
LogError("Failed to deflate stream to '%1'", GetFileName());
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return true;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
bool MinizCompressor::Finalize()
|
|
321
|
-
{
|
|
322
|
-
if (small_buf.len && !WriteDeflate(small_buf))
|
|
323
|
-
return false;
|
|
324
|
-
|
|
325
|
-
uint8_t dummy; // Avoid UB in miniz
|
|
326
|
-
tdefl_status status = tdefl_compress_buffer(&deflator, &dummy, 0, TDEFL_FINISH);
|
|
327
|
-
if (status != TDEFL_STATUS_DONE) {
|
|
328
|
-
if (status != TDEFL_STATUS_PUT_BUF_FAILED) {
|
|
329
|
-
LogError("Failed to end Deflate stream for '%1", GetFileName());
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
if (is_gzip) {
|
|
336
|
-
uint32_t gzip_footer[] = {
|
|
337
|
-
LittleEndian(crc32),
|
|
338
|
-
LittleEndian((uint32_t)uncompressed_size)
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
if (!WriteRaw(MakeSpan((uint8_t *)gzip_footer, RG_SIZE(gzip_footer))))
|
|
342
|
-
return false;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return true;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
RG_REGISTER_DECOMPRESSOR(CompressionType::Zlib, MinizDecompressor);
|
|
349
|
-
RG_REGISTER_DECOMPRESSOR(CompressionType::Gzip, MinizDecompressor);
|
|
350
|
-
RG_REGISTER_COMPRESSOR(CompressionType::Zlib, MinizCompressor);
|
|
351
|
-
RG_REGISTER_COMPRESSOR(CompressionType::Gzip, MinizCompressor);
|
|
352
|
-
|
|
353
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const spawn = require('child_process').spawnSync;
|
|
4
|
-
|
|
5
|
-
const filesToCheck = '*.js';
|
|
6
|
-
const FORMAT_START = process.env.FORMAT_START || 'main';
|
|
7
|
-
const IS_WIN = process.platform === 'win32';
|
|
8
|
-
const ESLINT_PATH = IS_WIN ? 'node_modules\\.bin\\eslint.cmd' : 'node_modules/.bin/eslint';
|
|
9
|
-
|
|
10
|
-
function main (args) {
|
|
11
|
-
let fix = false;
|
|
12
|
-
while (args.length > 0) {
|
|
13
|
-
switch (args[0]) {
|
|
14
|
-
case '-f':
|
|
15
|
-
case '--fix':
|
|
16
|
-
fix = true;
|
|
17
|
-
break;
|
|
18
|
-
default:
|
|
19
|
-
}
|
|
20
|
-
args.shift();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Check js files that change on unstaged file
|
|
24
|
-
const fileUnStaged = spawn(
|
|
25
|
-
'git',
|
|
26
|
-
['diff', '--name-only', '--diff-filter=d', FORMAT_START, filesToCheck],
|
|
27
|
-
{
|
|
28
|
-
encoding: 'utf-8'
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
// Check js files that change on staged file
|
|
33
|
-
const fileStaged = spawn(
|
|
34
|
-
'git',
|
|
35
|
-
['diff', '--name-only', '--cached', '--diff-filter=d', FORMAT_START, filesToCheck],
|
|
36
|
-
{
|
|
37
|
-
encoding: 'utf-8'
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const options = [
|
|
42
|
-
...fileStaged.stdout.split('\n').filter((f) => f !== ''),
|
|
43
|
-
...fileUnStaged.stdout.split('\n').filter((f) => f !== '')
|
|
44
|
-
];
|
|
45
|
-
|
|
46
|
-
if (fix) {
|
|
47
|
-
options.push('--fix');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const result = spawn(ESLINT_PATH, [...options], {
|
|
51
|
-
encoding: 'utf-8'
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
if (result.error && result.error.errno === 'ENOENT') {
|
|
55
|
-
console.error('Eslint not found! Eslint is supposed to be found at ', ESLINT_PATH);
|
|
56
|
-
return 2;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (result.status === 1) {
|
|
60
|
-
console.error('Eslint error:', result.stdout);
|
|
61
|
-
const fixCmd = 'npm run lint:fix';
|
|
62
|
-
console.error(`ERROR: please run "${fixCmd}" to format changes in your commit
|
|
63
|
-
Note that when running the command locally, please keep your local
|
|
64
|
-
main branch and working branch up to date with nodejs/node-addon-api
|
|
65
|
-
to exclude un-related complains.
|
|
66
|
-
Or you can run "env FORMAT_START=upstream/main ${fixCmd}".
|
|
67
|
-
Also fix JS files by yourself if necessary.`);
|
|
68
|
-
return 1;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (result.stderr) {
|
|
72
|
-
console.error('Error running eslint:', result.stderr);
|
|
73
|
-
return 2;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (require.main === module) {
|
|
78
|
-
process.exitCode = main(process.argv.slice(2));
|
|
79
|
-
}
|
|
File without changes
|