node-liblzma 1.1.5 → 1.1.6
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 +158 -180
- package/lib/lzma.js +384 -0
- package/package.json +6 -7
- package/prebuilds/darwin-x64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node_lzma.node +0 -0
- package/prebuilds/mac-x64/node_lzma.node +0 -0
- package/prebuilds/win-x64/node_lzma.node +0 -0
package/binding.gyp
CHANGED
|
@@ -4,98 +4,92 @@
|
|
|
4
4
|
# https://chromium.googlesource.com/external/github.com/grpc/grpc/+/refs/heads/chromium-deps/2016-08-17/binding.gyp
|
|
5
5
|
{
|
|
6
6
|
"variables": {
|
|
7
|
-
"use_global_liblzma": "
|
|
8
|
-
"runtime_link": "shared",
|
|
9
|
-
"
|
|
7
|
+
"use_global_liblzma%": "<!(node -p \"process.env.USE_GLOBAL || (!os.type().startsWith('Win'))\")",
|
|
8
|
+
"runtime_link%": "<!(node -p \"process.env.RUNTIME_LINK?.length > 0 ? process.env.RUNTIME_LINK : (!os.type().startsWith('Win') ? 'shared' : 'static')\")",
|
|
9
|
+
"enable_thread_support%": "<!(node -p \"process.env.ENABLE_THREAD_SUPPORT || 'yes'\")",
|
|
10
|
+
"xz_vendor_dir": "<(module_root_dir)/deps/xz",
|
|
10
11
|
"py3": "<!(node -p \"process.env.npm_config_python || 'python3'\")",
|
|
11
12
|
"target_dir": "<(module_root_dir)/build",
|
|
12
|
-
"prebuild_dir": "<(module_root_dir)/prebuilds/<(OS)-<(target_arch)/",
|
|
13
|
-
'conditions': [
|
|
14
|
-
['OS == "win"' , {
|
|
15
|
-
"runtime_link": "static", # Prefered method by default on Windows
|
|
16
|
-
"use_global_liblzma": "false" # Force download of Xz source code
|
|
17
|
-
}]
|
|
18
|
-
],
|
|
19
13
|
},
|
|
20
14
|
'target_defaults': {
|
|
21
15
|
'conditions': [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
['OS == "mac"', {
|
|
17
|
+
'xcode_settings': {
|
|
18
|
+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
|
19
|
+
'CLANG_CXX_LIBRARY': 'libc++',
|
|
20
|
+
'MACOSX_DEPLOYMENT_TARGET': '10.9',
|
|
21
|
+
'OTHER_CFLAGS': [
|
|
22
|
+
'-stdlib=libc++',
|
|
23
|
+
'-std=c++2a'
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
}],
|
|
33
27
|
['OS == "win"', {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
28
|
+
"msvs_disabled_warnings": [4275, 4005],
|
|
29
|
+
"configurations" : {
|
|
30
|
+
"Release" : {
|
|
31
|
+
"msvs_settings": {
|
|
32
|
+
"VCCLCompilerTool": {
|
|
33
|
+
"RuntimeLibrary": 0, # static release
|
|
34
|
+
"Optimization": 3,
|
|
35
|
+
"FavorSizeOrSpeed": 1,
|
|
36
|
+
"InlineFunctionExpansion": 2,
|
|
37
|
+
"WholeProgramOptimization": "true",
|
|
38
|
+
"OmitFramePointers": "true",
|
|
39
|
+
"EnableFunctionLevelLinking": "true",
|
|
40
|
+
"EnableIntrinsicFunctions": "true",
|
|
41
|
+
"RuntimeTypeInfo": "false",
|
|
42
|
+
"PreprocessorDefinitions": [
|
|
43
|
+
"WIN32_LEAN_AND_MEAN"
|
|
44
|
+
],
|
|
45
|
+
"ExceptionHandling": "0",
|
|
46
|
+
"AdditionalOptions": [
|
|
47
|
+
"/EHsc",
|
|
48
|
+
"/utf-8",
|
|
49
|
+
"/std:c++latest"
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
"VCLibrarianTool": {
|
|
53
|
+
"AdditionalOptions": [
|
|
54
|
+
"/LTCG"
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
"VCLinkerTool": {
|
|
58
|
+
"LinkTimeCodeGeneration": 1,
|
|
59
|
+
"OptimizeReferences": 2,
|
|
60
|
+
"EnableCOMDATFolding": 2,
|
|
61
|
+
"LinkIncremental": 1,
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
'defines': [ 'NDEBUG', '_NDEBUG' ],
|
|
65
|
+
},
|
|
66
|
+
"Debug": {
|
|
67
|
+
"msvs_settings": {
|
|
68
|
+
"VCCLCompilerTool": {
|
|
69
|
+
"PreprocessorDefinitions": [
|
|
70
|
+
"WIN32_LEAN_AND_MEAN"
|
|
71
|
+
],
|
|
72
|
+
"ExceptionHandling": "0",
|
|
73
|
+
"AdditionalOptions": [
|
|
74
|
+
"/EHsc",
|
|
75
|
+
"/utf-8",
|
|
76
|
+
"/std:c++latest"
|
|
77
|
+
],
|
|
78
|
+
'RuntimeLibrary': 1, # static debug
|
|
79
|
+
},
|
|
80
|
+
"VCLibrarianTool": {
|
|
81
|
+
"AdditionalOptions": [
|
|
82
|
+
"/LTCG",
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
"VCLinkerTool": {
|
|
86
|
+
"LinkTimeCodeGeneration": 1,
|
|
87
|
+
"LinkIncremental": 1,
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
'defines': [ 'DEBUG', '_DEBUG' ],
|
|
91
|
+
}
|
|
92
|
+
},
|
|
99
93
|
"defines": [
|
|
100
94
|
'_WIN32_WINNT=0x0600',
|
|
101
95
|
'_HAS_EXCEPTIONS=0',
|
|
@@ -117,12 +111,12 @@
|
|
|
117
111
|
"defines": [
|
|
118
112
|
"_GLIBCXX_USE_CXX11_ABI=1",
|
|
119
113
|
]
|
|
120
|
-
|
|
114
|
+
}]
|
|
121
115
|
]
|
|
122
116
|
},
|
|
123
117
|
'conditions': [
|
|
124
118
|
[ 'use_global_liblzma == "false"', {
|
|
125
|
-
|
|
119
|
+
# Compile liblzma from here
|
|
126
120
|
'conditions': [
|
|
127
121
|
[
|
|
128
122
|
'OS == "win"', {
|
|
@@ -137,29 +131,29 @@
|
|
|
137
131
|
'inputs': [''],
|
|
138
132
|
'outputs': ["<(xz_vendor_dir)/autogen.sh"],
|
|
139
133
|
'action': [
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
134
|
+
"<!(node -p \"process.env.npm_config_python || 'python3'\")",
|
|
135
|
+
"<(module_root_dir)/scripts/download_extract_deps.py",
|
|
136
|
+
"<(module_root_dir)/deps/xz.tar.xz",
|
|
137
|
+
"<(module_root_dir)/deps/"
|
|
138
|
+
]
|
|
145
139
|
}
|
|
146
140
|
],
|
|
147
141
|
},
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
142
|
+
]
|
|
143
|
+
}],
|
|
144
|
+
[
|
|
145
|
+
'OS == "win" and runtime_link == "shared"', {
|
|
146
|
+
'targets': [
|
|
153
147
|
{
|
|
154
148
|
'target_name': 'lzma',
|
|
155
149
|
'product_prefix': 'lib',
|
|
156
|
-
|
|
157
|
-
|
|
150
|
+
'type': 'shared_library',
|
|
151
|
+
'hard_dependency': 1,
|
|
158
152
|
'defines': [
|
|
159
153
|
"WIN32",
|
|
160
154
|
"HAVE_CONFIG_H",
|
|
161
|
-
|
|
162
|
-
|
|
155
|
+
"LIBLZMADLL_EXPORTS",
|
|
156
|
+
"DLL_EXPORT"
|
|
163
157
|
],
|
|
164
158
|
"include_dirs": [
|
|
165
159
|
"<(xz_vendor_dir)/src",
|
|
@@ -317,16 +311,16 @@
|
|
|
317
311
|
"<(xz_vendor_dir)/windows/vs2019/config.h",
|
|
318
312
|
]
|
|
319
313
|
},
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
314
|
+
],
|
|
315
|
+
}],
|
|
316
|
+
[
|
|
317
|
+
'OS == "win" and runtime_link == "static"', {
|
|
318
|
+
'targets': [
|
|
325
319
|
{
|
|
326
320
|
'target_name': 'lzma',
|
|
327
321
|
'product_prefix': 'lib',
|
|
328
322
|
'type': 'static_library',
|
|
329
|
-
|
|
323
|
+
'hard_dependency': 1,
|
|
330
324
|
'defines': [
|
|
331
325
|
"WIN32",
|
|
332
326
|
"HAVE_CONFIG_H",
|
|
@@ -503,10 +497,10 @@
|
|
|
503
497
|
'inputs': [''],
|
|
504
498
|
'outputs': ["<(xz_vendor_dir)/autogen.sh"],
|
|
505
499
|
'action': [
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
500
|
+
"<!(node -p \"process.env.npm_config_python || 'python3'\")",
|
|
501
|
+
"<(module_root_dir)/scripts/download_extract_deps.py",
|
|
502
|
+
"<(module_root_dir)/deps/xz.tar.xz",
|
|
503
|
+
"<(module_root_dir)/deps/"
|
|
510
504
|
]
|
|
511
505
|
}
|
|
512
506
|
],
|
|
@@ -522,15 +516,16 @@
|
|
|
522
516
|
'inputs': [''],
|
|
523
517
|
'outputs': [''],
|
|
524
518
|
'action': [
|
|
525
|
-
'sh', '-c', 'cd <(xz_vendor_dir) && ./configure --enable-static --
|
|
526
|
-
|
|
527
|
-
|
|
519
|
+
'sh', '-c', 'cd <(xz_vendor_dir) && ./configure --enable-static --enable-shared --disable-scripts --disable-lzmainfo \
|
|
520
|
+
--disable-lzma-links --disable-lzmadec --disable-xzdec --disable-xz --disable-rpath --enable-threads=<(enable_thread_support) \
|
|
521
|
+
--disable-dependency-tracking --prefix="<(target_dir)/liblzma" && make && make install'
|
|
528
522
|
]
|
|
529
523
|
}
|
|
530
524
|
],
|
|
531
525
|
},
|
|
532
526
|
],
|
|
533
|
-
}
|
|
527
|
+
}
|
|
528
|
+
]
|
|
534
529
|
],
|
|
535
530
|
}]
|
|
536
531
|
],
|
|
@@ -543,7 +538,7 @@
|
|
|
543
538
|
"NAPI_DISABLE_CPP_EXCEPTIONS"
|
|
544
539
|
],
|
|
545
540
|
'cflags': [
|
|
546
|
-
'-std=c++2a',
|
|
541
|
+
'-std=c++2a', # because GCC 9 and earlier do not support -std=c++20
|
|
547
542
|
'-Wall',
|
|
548
543
|
'-pthread',
|
|
549
544
|
'-g',
|
|
@@ -558,39 +553,44 @@
|
|
|
558
553
|
"conditions": [
|
|
559
554
|
[
|
|
560
555
|
'runtime_link == "static"', {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
556
|
+
"dependencies": [
|
|
557
|
+
"lzma"
|
|
558
|
+
],
|
|
559
|
+
'msvs_settings': {
|
|
560
|
+
'VCLinkerTool': {
|
|
561
|
+
'AdditionalOptions': [
|
|
562
|
+
'/WHOLEARCHIVE:liblzma<(STATIC_LIB_SUFFIX)',
|
|
563
|
+
'/FORCE:MULTIPLE'
|
|
564
|
+
],
|
|
565
|
+
},
|
|
566
|
+
}
|
|
572
567
|
}, {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
568
|
+
"dependencies": [
|
|
569
|
+
"lzma"
|
|
570
|
+
],
|
|
571
|
+
}]
|
|
572
|
+
],
|
|
573
|
+
"include_dirs": [
|
|
574
|
+
"<(xz_vendor_dir)/src",
|
|
575
|
+
"<(xz_vendor_dir)/windows/vs2019",
|
|
576
|
+
"<(xz_vendor_dir)/src/liblzma/common",
|
|
577
|
+
"<(xz_vendor_dir)/src/common",
|
|
578
|
+
"<(xz_vendor_dir)/src/liblzma/api",
|
|
579
|
+
"<(xz_vendor_dir)/src/liblzma/check",
|
|
580
|
+
"<(xz_vendor_dir)/src/liblzma/delta",
|
|
581
|
+
"<(xz_vendor_dir)/src/liblzma/lz",
|
|
582
|
+
"<(xz_vendor_dir)/src/liblzma/lzma",
|
|
583
|
+
"<(xz_vendor_dir)/src/liblzma/rangecoder",
|
|
584
|
+
"<(xz_vendor_dir)/src/liblzma/simple"
|
|
585
|
+
],
|
|
591
586
|
}],
|
|
592
587
|
['OS=="linux" or OS=="mac"', {
|
|
593
588
|
"conditions": [
|
|
589
|
+
[ 'enable_thread_support != "no"', {
|
|
590
|
+
'defines': [
|
|
591
|
+
"ENABLE_THREAD_SUPPORT"
|
|
592
|
+
]
|
|
593
|
+
}],
|
|
594
594
|
[
|
|
595
595
|
'use_global_liblzma == "true"', {
|
|
596
596
|
# Use pkg-config for include and lib
|
|
@@ -627,17 +627,17 @@
|
|
|
627
627
|
'include_dirs': [
|
|
628
628
|
"<(target_dir)/liblzma/include",
|
|
629
629
|
],
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
630
|
+
"library_dirs": [
|
|
631
|
+
"<(target_dir)/liblzma/lib",
|
|
632
|
+
],
|
|
633
|
+
'ldflags': [
|
|
634
|
+
'-Wl,--whole-archive',
|
|
635
|
+
'-l:liblzma.a',
|
|
636
|
+
'-Wl,--no-whole-archive',
|
|
637
|
+
],
|
|
638
|
+
'defines': [
|
|
639
|
+
"LZMA_API_STATIC",
|
|
640
|
+
],
|
|
641
641
|
'dependencies': [
|
|
642
642
|
'lzma'
|
|
643
643
|
]
|
|
@@ -653,28 +653,6 @@
|
|
|
653
653
|
"dependencies": [
|
|
654
654
|
"<!(node -p \"require('node-addon-api').gyp\")",
|
|
655
655
|
],
|
|
656
|
-
|
|
657
|
-
{
|
|
658
|
-
'target_name': 'prebuildify',
|
|
659
|
-
'type': 'none',
|
|
660
|
-
'dependencies': [
|
|
661
|
-
'node_lzma'
|
|
662
|
-
],
|
|
663
|
-
'actions': [
|
|
664
|
-
{
|
|
665
|
-
'action_name': 'prebuildify',
|
|
666
|
-
'inputs': [
|
|
667
|
-
'<(PRODUCT_DIR)/node_lzma.node',
|
|
668
|
-
],
|
|
669
|
-
'outputs': ['<(prebuild_dir)'],
|
|
670
|
-
'action': [
|
|
671
|
-
"<!(node -p \"process.env.npm_config_python || 'python3'\")",
|
|
672
|
-
"<(module_root_dir)/scripts/prebuildify.py",
|
|
673
|
-
"<(PRODUCT_DIR)/node_lzma.node",
|
|
674
|
-
"<(prebuild_dir)/node_lzma.node"
|
|
675
|
-
]
|
|
676
|
-
}
|
|
677
|
-
]
|
|
678
|
-
}
|
|
656
|
+
},
|
|
679
657
|
]
|
|
680
658
|
}
|
package/lib/lzma.js
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.6.1
|
|
2
|
+
(function() {
|
|
3
|
+
/*
|
|
4
|
+
* node-liblzma - Node.js bindings for liblzma
|
|
5
|
+
* Copyright (C) Olivier Orabona <olivier.orabona@gmail.com>
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
18
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
var Transform, Unxz, Xz, XzStream, assert, binding_path, liblzma, maxThreads, os, path, util, xzBuffer, xzBufferSync;
|
|
21
|
+
|
|
22
|
+
path = require('path');
|
|
23
|
+
|
|
24
|
+
binding_path = path.resolve(path.join(__dirname, '..'));
|
|
25
|
+
|
|
26
|
+
liblzma = require('node-gyp-build')(binding_path);
|
|
27
|
+
|
|
28
|
+
util = require('util');
|
|
29
|
+
|
|
30
|
+
assert = require('assert');
|
|
31
|
+
|
|
32
|
+
os = require('os');
|
|
33
|
+
|
|
34
|
+
({Transform} = require('stream'));
|
|
35
|
+
|
|
36
|
+
// Should not change over time... :)
|
|
37
|
+
maxThreads = os.cpus().length;
|
|
38
|
+
|
|
39
|
+
XzStream = class XzStream extends Transform {
|
|
40
|
+
constructor(mode, _opts = {}, options) {
|
|
41
|
+
var base, base1, base2, base3, base4;
|
|
42
|
+
super(options);
|
|
43
|
+
this._opts = _opts;
|
|
44
|
+
if ((base = this._opts).check == null) {
|
|
45
|
+
base.check = exports.check.NONE;
|
|
46
|
+
}
|
|
47
|
+
if ((base1 = this._opts).preset == null) {
|
|
48
|
+
base1.preset = exports.preset.DEFAULT;
|
|
49
|
+
}
|
|
50
|
+
if ((base2 = this._opts).filters == null) {
|
|
51
|
+
base2.filters = [exports.filter.LZMA2];
|
|
52
|
+
}
|
|
53
|
+
if ((base3 = this._opts).mode == null) {
|
|
54
|
+
base3.mode = exports.mode.NORMAL;
|
|
55
|
+
}
|
|
56
|
+
if ((base4 = this._opts).threads == null) {
|
|
57
|
+
base4.threads = 1;
|
|
58
|
+
}
|
|
59
|
+
this._chunkSize = this._opts.chunkSize ? this._opts.chunkSize : liblzma.BUFSIZ;
|
|
60
|
+
// By default no flush, since there is no LZMA_NO_SYNC, we stick to
|
|
61
|
+
// default LZMA_RUN (0)
|
|
62
|
+
this._flushFlag = this._opts.flushFlag || liblzma.LZMA_RUN;
|
|
63
|
+
assert(Array.isArray(this._opts.filters), "Filters need to be in an array!");
|
|
64
|
+
// Add default filter LZMA2 if none provided
|
|
65
|
+
if (this._opts.filters.indexOf(exports.filter.LZMA2) === -1) {
|
|
66
|
+
this._opts.filters.push(exports.filter.LZMA2);
|
|
67
|
+
}
|
|
68
|
+
// Multithreading is only available for encoding, so if we are encoding, check
|
|
69
|
+
// opts threads value.
|
|
70
|
+
if (mode === liblzma.STREAM_ENCODE) {
|
|
71
|
+
if (!liblzma.HAS_THREADS_SUPPORT) {
|
|
72
|
+
this._opts.threads = 1;
|
|
73
|
+
}
|
|
74
|
+
// By default set to maximum available processors
|
|
75
|
+
if (this._opts.threads === 0) {
|
|
76
|
+
this._opts.threads = maxThreads;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Initialize engine
|
|
80
|
+
this.lzma = new liblzma.LZMA(mode, this._opts);
|
|
81
|
+
this._closed = false;
|
|
82
|
+
this._hadError = false;
|
|
83
|
+
this._offset = 0;
|
|
84
|
+
this._buffer = Buffer.alloc(this._chunkSize);
|
|
85
|
+
this.on('onerror', (errno) => {
|
|
86
|
+
var error;
|
|
87
|
+
this._hadError = true;
|
|
88
|
+
error = new Error(exports.messages[errno]);
|
|
89
|
+
error.errno = errno;
|
|
90
|
+
error.code = errno;
|
|
91
|
+
return this.emit('error', error);
|
|
92
|
+
});
|
|
93
|
+
this.once('end', this.close);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
flush(kind, callback) {
|
|
97
|
+
var ws;
|
|
98
|
+
ws = this._writableState;
|
|
99
|
+
if (typeof kind === 'function' || (typeof kind === 'undefined' && !callback)) {
|
|
100
|
+
[callback, kind] = [kind, liblzma.LZMA_SYNC_FLUSH];
|
|
101
|
+
}
|
|
102
|
+
if (ws.ended) {
|
|
103
|
+
if (callback) {
|
|
104
|
+
process.nextTick(callback);
|
|
105
|
+
}
|
|
106
|
+
} else if (ws.ending) {
|
|
107
|
+
if (callback) {
|
|
108
|
+
this.once('end', callback);
|
|
109
|
+
}
|
|
110
|
+
} else if (ws.needDrain) {
|
|
111
|
+
this.once('drain', () => {
|
|
112
|
+
this.flush(callback);
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
this._flushFlag = kind;
|
|
116
|
+
this.write(Buffer.alloc(0), '', callback);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
close(callback) {
|
|
121
|
+
if (callback) {
|
|
122
|
+
process.nextTick(callback);
|
|
123
|
+
}
|
|
124
|
+
// We will trigger this case with #xz and #unxz
|
|
125
|
+
if (this._closed) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.lzma.close();
|
|
129
|
+
this._closed = true;
|
|
130
|
+
process.nextTick(() => {
|
|
131
|
+
this.emit('close');
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
_transform(chunk, encoding, callback) {
|
|
136
|
+
var ending, flushFlag, last, ws;
|
|
137
|
+
flushFlag = void 0;
|
|
138
|
+
ws = this._writableState;
|
|
139
|
+
ending = ws.ending || ws.ended;
|
|
140
|
+
last = ending && (!chunk || ws.length === chunk.length);
|
|
141
|
+
if (chunk !== null && !(chunk instanceof Buffer)) {
|
|
142
|
+
return callback(new Error("invalid input"));
|
|
143
|
+
}
|
|
144
|
+
if (this._closed) {
|
|
145
|
+
return callback(new Error("lzma binding closed"));
|
|
146
|
+
}
|
|
147
|
+
// If it's the last chunk, or a final flush, we use the LZMA_FINISH flush flag.
|
|
148
|
+
// If it's explicitly flushing at some other time, then we use
|
|
149
|
+
// LZMA_SYNC_FLUSH.
|
|
150
|
+
if (last) {
|
|
151
|
+
flushFlag = liblzma.LZMA_FINISH;
|
|
152
|
+
} else {
|
|
153
|
+
flushFlag = this._flushFlag;
|
|
154
|
+
if (chunk.length >= ws.length) {
|
|
155
|
+
// once we've flushed the last of the queue, stop flushing and
|
|
156
|
+
// go back to the normal behavior.
|
|
157
|
+
this._flushFlag = this._opts.flushFlag || liblzma.LZMA_RUN;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
this._processChunk(chunk, flushFlag, callback);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
_flush(callback) {
|
|
164
|
+
this._transform(Buffer.alloc(0), '', callback);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
_processChunk(chunk, flushFlag, cb) {
|
|
168
|
+
var async, availInBefore, availOutBefore, buf, buffers, callback, error, inOff, nread, res;
|
|
169
|
+
// If user setting async is set to true, then it will all depend on whether
|
|
170
|
+
// we can actually be async, or not. If user set explicitly async to false
|
|
171
|
+
// then whether we have a callback or not becomes irrelevant..
|
|
172
|
+
// TODO: Works in v0.11
|
|
173
|
+
//async = util.isFunction cb
|
|
174
|
+
// until then...
|
|
175
|
+
async = typeof cb === 'function';
|
|
176
|
+
// Sanity checks
|
|
177
|
+
assert(!this._closed, "Stream closed!");
|
|
178
|
+
availInBefore = chunk && chunk.length;
|
|
179
|
+
availOutBefore = this._chunkSize - this._offset;
|
|
180
|
+
inOff = 0;
|
|
181
|
+
// So far it looks like Zlib _processChunk in CoffeeScript. But to make C++
|
|
182
|
+
// code easier when it comes to emitting events and callback calling sync/async
|
|
183
|
+
// we handle error codes here. If anything wrong is returned, we emit event
|
|
184
|
+
// and return false in case we are synchronous.
|
|
185
|
+
callback = (errno, availInAfter, availOutAfter) => {
|
|
186
|
+
var out, used;
|
|
187
|
+
if (this._hadError) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
// if LZMA engine returned something else, we are running into trouble!
|
|
191
|
+
if (errno !== liblzma.LZMA_OK && errno !== liblzma.LZMA_STREAM_END) {
|
|
192
|
+
this.emit('onerror', errno);
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
used = availOutBefore - availOutAfter;
|
|
196
|
+
assert(used >= 0, `More bytes after than before! Delta = ${used}`);
|
|
197
|
+
if (used > 0) {
|
|
198
|
+
out = this._buffer.slice(this._offset, this._offset + used);
|
|
199
|
+
this._offset += used;
|
|
200
|
+
if (async) {
|
|
201
|
+
this.push(out);
|
|
202
|
+
} else {
|
|
203
|
+
buffers.push(out);
|
|
204
|
+
nread += used;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// exhausted the output buffer, or used all the input create a new one.
|
|
208
|
+
if (availOutAfter === 0 || this._offset >= this._chunkSize) {
|
|
209
|
+
availOutBefore = this._chunkSize;
|
|
210
|
+
this._offset = 0;
|
|
211
|
+
this._buffer = Buffer.alloc(this._chunkSize);
|
|
212
|
+
}
|
|
213
|
+
if (availOutAfter === 0 || availInAfter > 0) {
|
|
214
|
+
inOff += availInBefore - availInAfter;
|
|
215
|
+
availInBefore = availInAfter;
|
|
216
|
+
if (!async) {
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
this.lzma.code(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset, callback);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (!async) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
cb();
|
|
226
|
+
};
|
|
227
|
+
if (!async) {
|
|
228
|
+
// Doing it synchronously
|
|
229
|
+
buffers = [];
|
|
230
|
+
nread = 0;
|
|
231
|
+
error = null;
|
|
232
|
+
this.on('error', function(e) {
|
|
233
|
+
return error = e;
|
|
234
|
+
});
|
|
235
|
+
while (true) {
|
|
236
|
+
res = this.lzma.codeSync(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset);
|
|
237
|
+
if (!(!this._hadError && callback(res[0], res[1], res[2]))) {
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (this._hadError) {
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
this.close();
|
|
245
|
+
buf = Buffer.concat(buffers, nread);
|
|
246
|
+
return buf;
|
|
247
|
+
}
|
|
248
|
+
this.lzma.code(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset, callback);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
Xz = class Xz extends XzStream {
|
|
254
|
+
constructor(lzma_options, options) {
|
|
255
|
+
super(liblzma.STREAM_ENCODE, lzma_options, options);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
Unxz = class Unxz extends XzStream {
|
|
261
|
+
constructor(lzma_options, options) {
|
|
262
|
+
super(liblzma.STREAM_DECODE, lzma_options, options);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
exports.Xz = Xz;
|
|
268
|
+
|
|
269
|
+
exports.Unxz = Unxz;
|
|
270
|
+
|
|
271
|
+
exports.hasThreads = function() {
|
|
272
|
+
return liblzma.HAS_THREADS_SUPPORT;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
exports.messages = ["Operation completed successfully", "End of stream was reached", "Input stream has no integrity check", "Cannot calculate the integrity check", "Integrity check type is not available", "Cannot allocate memory", "Memory usage limit was reached", "File format not recognized", "Invalid or unsupported options", "Data is corrupt", "No progress is possible", "Programming error"];
|
|
276
|
+
|
|
277
|
+
exports.check = {
|
|
278
|
+
"NONE": liblzma.LZMA_CHECK_NONE,
|
|
279
|
+
"CRC32": liblzma.LZMA_CHECK_CRC32,
|
|
280
|
+
"CRC64": liblzma.LZMA_CHECK_CRC64,
|
|
281
|
+
"SHA256": liblzma.LZMA_CHECK_SHA256
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
exports.preset = {
|
|
285
|
+
"DEFAULT": liblzma.LZMA_PRESET_DEFAULT,
|
|
286
|
+
"EXTREME": liblzma.LZMA_PRESET_EXTREME
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
exports.flag = {
|
|
290
|
+
"TELL_NO_CHECK": liblzma.LZMA_TELL_NO_CHECK,
|
|
291
|
+
"TELL_UNSUPPORTED_CHECK": liblzma.LZMA_TELL_UNSUPPORTED_CHECK,
|
|
292
|
+
"TELL_ANY_CHECK": liblzma.LZMA_TELL_ANY_CHECK,
|
|
293
|
+
"CONCATENATED": liblzma.LZMA_CONCATENATED
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
exports.filter = {
|
|
297
|
+
"LZMA2": liblzma.LZMA_FILTER_LZMA2,
|
|
298
|
+
"X86": liblzma.LZMA_FILTER_X86,
|
|
299
|
+
"POWERPC": liblzma.LZMA_FILTER_POWERPC,
|
|
300
|
+
"IA64": liblzma.LZMA_FILTER_IA64,
|
|
301
|
+
"ARM": liblzma.LZMA_FILTER_ARM,
|
|
302
|
+
"ARMTHUMB": liblzma.LZMA_FILTER_ARMTHUMB,
|
|
303
|
+
"SPARC": liblzma.LZMA_FILTER_SPARC
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
exports.mode = {
|
|
307
|
+
"FAST": liblzma.LZMA_MODE_FAST,
|
|
308
|
+
"NORMAL": liblzma.LZMA_MODE_NORMAL
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
exports.createXz = function(lzma_options, options) {
|
|
312
|
+
return new Xz(lzma_options, options);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
exports.createUnxz = function(lzma_options, options) {
|
|
316
|
+
return new Unxz(lzma_options, options);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
exports.unxz = function(buffer, opts, callback) {
|
|
320
|
+
if (typeof opts === 'function') {
|
|
321
|
+
[callback, opts] = [opts, {}];
|
|
322
|
+
}
|
|
323
|
+
return xzBuffer(new Unxz(opts), buffer, callback);
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
exports.unxzSync = function(buffer, opts) {
|
|
327
|
+
return xzBufferSync(new Unxz(opts), buffer);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
exports.xz = function(buffer, opts, callback) {
|
|
331
|
+
if (typeof opts === 'function') {
|
|
332
|
+
[callback, opts] = [opts, {}];
|
|
333
|
+
}
|
|
334
|
+
return xzBuffer(new Xz(opts), buffer, callback);
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
exports.xzSync = function(buffer, opts) {
|
|
338
|
+
return xzBufferSync(new Xz(opts), buffer);
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
xzBuffer = function(engine, buffer, callback) {
|
|
342
|
+
var buffers, flow, nread, onEnd, onError;
|
|
343
|
+
buffers = [];
|
|
344
|
+
nread = 0;
|
|
345
|
+
flow = function() {
|
|
346
|
+
var chunk;
|
|
347
|
+
chunk = void 0;
|
|
348
|
+
while (null !== (chunk = engine.read())) {
|
|
349
|
+
buffers.push(chunk);
|
|
350
|
+
nread += chunk.length;
|
|
351
|
+
}
|
|
352
|
+
engine.once('readable', flow);
|
|
353
|
+
};
|
|
354
|
+
onEnd = function() {
|
|
355
|
+
var buf;
|
|
356
|
+
buf = Buffer.concat(buffers, nread);
|
|
357
|
+
buffers = [];
|
|
358
|
+
callback(null, buf);
|
|
359
|
+
engine.close();
|
|
360
|
+
};
|
|
361
|
+
onError = function(err) {
|
|
362
|
+
engine.removeListener('end', onEnd);
|
|
363
|
+
engine.removeListener('readable', flow);
|
|
364
|
+
callback(err);
|
|
365
|
+
};
|
|
366
|
+
engine.on('error', onError);
|
|
367
|
+
engine.on('end', onEnd);
|
|
368
|
+
engine.end(buffer);
|
|
369
|
+
flow();
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
xzBufferSync = function(engine, buffer) {
|
|
373
|
+
if (typeof buffer === 'string') {
|
|
374
|
+
buffer = Buffer.from(buffer);
|
|
375
|
+
}
|
|
376
|
+
if (!(buffer instanceof Buffer)) {
|
|
377
|
+
throw new TypeError("Not a string or buffer");
|
|
378
|
+
}
|
|
379
|
+
return engine._processChunk(buffer, liblzma.LZMA_FINISH);
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
module.exports = exports;
|
|
383
|
+
|
|
384
|
+
}).call(this);
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-liblzma",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "NodeJS wrapper for liblzma",
|
|
5
5
|
"main": "./lib/lzma.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"install": "node-gyp
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"test": "
|
|
7
|
+
"install": "node-gyp-build",
|
|
8
|
+
"prepare": "npx ynpx coffeescript --compile --output lib/ src/",
|
|
9
|
+
"prebuildify": "npx prebuildify --napi --strip -t $(node -v)",
|
|
10
|
+
"prebuildify:win": "for /f \"usebackq tokens=*\" %v in (`node -v`) do npx prebuildify -t %v --napi --strip",
|
|
11
|
+
"test": "mocha test/*.coffee"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"node-addon-api": "4.2.0",
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"coffeescript": "2.6.1",
|
|
19
19
|
"expect.js": "0.3.1",
|
|
20
20
|
"mocha": "9.2.1",
|
|
21
|
-
"node-gyp": "8.4.1",
|
|
22
21
|
"tsd": "0.19.1"
|
|
23
22
|
},
|
|
24
23
|
"types": "index.d.ts",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|