node-liblzma 1.0.4-9 → 1.1.5
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/History.md +5 -0
- package/README.md +199 -0
- package/binding.gyp +671 -43
- package/package.json +35 -23
- 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/scripts/download_extract_deps.py +29 -0
- package/scripts/prebuildify.py +13 -0
- package/scripts/walk_sources.py +7 -0
- package/build.yml +0 -78
- package/lib/lzma.js +0 -381
- package/src/bindings/module.cpp +0 -107
- package/src/bindings/node-liblzma.cpp +0 -320
- package/src/bindings/node-liblzma.hpp +0 -115
- package/src/lzma.coffee +0 -339
package/src/bindings/module.cpp
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* node-liblzma - Node.js bindings for liblzma
|
|
3
|
-
* Copyright (C) 2014-2015 Olivier Orabona <olivier.orabona@gmail.com>
|
|
4
|
-
*
|
|
5
|
-
* This program is free software: you can redistribute it and/or modify
|
|
6
|
-
* it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
* (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This program is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
* GNU General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
-
**/
|
|
18
|
-
|
|
19
|
-
#include "node-liblzma.hpp"
|
|
20
|
-
|
|
21
|
-
using namespace v8;
|
|
22
|
-
|
|
23
|
-
void moduleInit(Local<Object> exports) {
|
|
24
|
-
LZMA::Init(exports);
|
|
25
|
-
|
|
26
|
-
// enum lzma_ret
|
|
27
|
-
exports->Set(NewString("LZMA_OK"), Nan::New<Number>(LZMA_OK));
|
|
28
|
-
exports->Set(NewString("LZMA_STREAM_END"), Nan::New<Number>(LZMA_STREAM_END));
|
|
29
|
-
exports->Set(NewString("LZMA_NO_CHECK"), Nan::New<Number>(LZMA_NO_CHECK));
|
|
30
|
-
exports->Set(NewString("LZMA_UNSUPPORTED_CHECK"), Nan::New<Number>(LZMA_UNSUPPORTED_CHECK));
|
|
31
|
-
exports->Set(NewString("LZMA_GET_CHECK"), Nan::New<Number>(LZMA_GET_CHECK));
|
|
32
|
-
exports->Set(NewString("LZMA_MEM_ERROR"), Nan::New<Number>(LZMA_MEM_ERROR));
|
|
33
|
-
exports->Set(NewString("LZMA_MEMLIMIT_ERROR"), Nan::New<Number>(LZMA_MEMLIMIT_ERROR));
|
|
34
|
-
exports->Set(NewString("LZMA_FORMAT_ERROR"), Nan::New<Number>(LZMA_FORMAT_ERROR));
|
|
35
|
-
exports->Set(NewString("LZMA_OPTIONS_ERROR"), Nan::New<Number>(LZMA_OPTIONS_ERROR));
|
|
36
|
-
exports->Set(NewString("LZMA_DATA_ERROR"), Nan::New<Number>(LZMA_DATA_ERROR));
|
|
37
|
-
exports->Set(NewString("LZMA_BUF_ERROR"), Nan::New<Number>(LZMA_BUF_ERROR));
|
|
38
|
-
exports->Set(NewString("LZMA_PROG_ERROR"), Nan::New<Number>(LZMA_PROG_ERROR));
|
|
39
|
-
|
|
40
|
-
// enum lzma_action
|
|
41
|
-
exports->Set(NewString("LZMA_RUN"), Nan::New<Number>(LZMA_RUN));
|
|
42
|
-
exports->Set(NewString("LZMA_SYNC_FLUSH"), Nan::New<Number>(LZMA_SYNC_FLUSH));
|
|
43
|
-
exports->Set(NewString("LZMA_FULL_FLUSH"), Nan::New<Number>(LZMA_FULL_FLUSH));
|
|
44
|
-
exports->Set(NewString("LZMA_FINISH"), Nan::New<Number>(LZMA_FINISH));
|
|
45
|
-
|
|
46
|
-
// enum lzma_check
|
|
47
|
-
exports->Set(NewString("LZMA_CHECK_NONE"), Nan::New<Number>(LZMA_CHECK_NONE));
|
|
48
|
-
exports->Set(NewString("LZMA_CHECK_CRC32"), Nan::New<Number>(LZMA_CHECK_CRC32));
|
|
49
|
-
exports->Set(NewString("LZMA_CHECK_CRC64"), Nan::New<Number>(LZMA_CHECK_CRC64));
|
|
50
|
-
exports->Set(NewString("LZMA_CHECK_SHA256"), Nan::New<Number>(LZMA_CHECK_SHA256));
|
|
51
|
-
|
|
52
|
-
// lzma_match_finder
|
|
53
|
-
exports->Set(NewString("MF_HC3"), Nan::New<Number>(LZMA_MF_HC3));
|
|
54
|
-
exports->Set(NewString("MF_HC4"), Nan::New<Number>(LZMA_MF_HC4));
|
|
55
|
-
exports->Set(NewString("MF_BT2"), Nan::New<Number>(LZMA_MF_BT2));
|
|
56
|
-
exports->Set(NewString("MF_BT3"), Nan::New<Number>(LZMA_MF_BT3));
|
|
57
|
-
exports->Set(NewString("MF_BT4"), Nan::New<Number>(LZMA_MF_BT4));
|
|
58
|
-
|
|
59
|
-
// lzma_mode
|
|
60
|
-
exports->Set(NewString("LZMA_MODE_FAST"), Nan::New<Number>(LZMA_MODE_FAST));
|
|
61
|
-
exports->Set(NewString("LZMA_MODE_NORMAL"), Nan::New<Number>(LZMA_MODE_NORMAL));
|
|
62
|
-
|
|
63
|
-
// defines
|
|
64
|
-
exports->Set(NewString("LZMA_FILTER_X86"), Nan::New<Number>(LZMA_FILTER_X86));
|
|
65
|
-
exports->Set(NewString("LZMA_FILTER_POWERPC"), Nan::New<Number>(LZMA_FILTER_POWERPC));
|
|
66
|
-
exports->Set(NewString("LZMA_FILTER_IA64"), Nan::New<Number>(LZMA_FILTER_IA64));
|
|
67
|
-
exports->Set(NewString("LZMA_FILTER_ARM"), Nan::New<Number>(LZMA_FILTER_ARM));
|
|
68
|
-
exports->Set(NewString("LZMA_FILTER_ARMTHUMB"), Nan::New<Number>(LZMA_FILTER_ARMTHUMB));
|
|
69
|
-
exports->Set(NewString("LZMA_FILTER_SPARC"), Nan::New<Number>(LZMA_FILTER_SPARC));
|
|
70
|
-
exports->Set(NewString("LZMA_FILTER_DELTA"), Nan::New<Number>(LZMA_FILTER_DELTA));
|
|
71
|
-
exports->Set(NewString("LZMA_FILTERS_MAX"), Nan::New<Number>(LZMA_FILTERS_MAX));
|
|
72
|
-
exports->Set(NewString("LZMA_FILTER_LZMA1"), Nan::New<Number>(LZMA_FILTER_LZMA1));
|
|
73
|
-
exports->Set(NewString("LZMA_FILTER_LZMA2"), Nan::New<Number>(LZMA_FILTER_LZMA2));
|
|
74
|
-
exports->Set(NewString("LZMA_VLI_UNKNOWN"), Nan::New<Number>(LZMA_VLI_UNKNOWN));
|
|
75
|
-
|
|
76
|
-
exports->Set(NewString("LZMA_VLI_BYTES_MAX"), Nan::New<Number>(LZMA_VLI_BYTES_MAX));
|
|
77
|
-
exports->Set(NewString("LZMA_CHECK_ID_MAX"), Nan::New<Number>(LZMA_CHECK_ID_MAX));
|
|
78
|
-
exports->Set(NewString("LZMA_CHECK_SIZE_MAX"), Nan::New<Number>(LZMA_CHECK_SIZE_MAX));
|
|
79
|
-
exports->Set(NewString("LZMA_PRESET_DEFAULT"), Nan::New<Number>(LZMA_PRESET_DEFAULT));
|
|
80
|
-
exports->Set(NewString("LZMA_PRESET_LEVEL_MASK"), Nan::New<Number>(LZMA_PRESET_LEVEL_MASK));
|
|
81
|
-
exports->Set(NewString("LZMA_PRESET_EXTREME"), Nan::New<Number>(LZMA_PRESET_EXTREME));
|
|
82
|
-
exports->Set(NewString("LZMA_TELL_NO_CHECK"), Nan::New<Number>(LZMA_TELL_NO_CHECK));
|
|
83
|
-
exports->Set(NewString("LZMA_TELL_UNSUPPORTED_CHECK"), Nan::New<Number>(LZMA_TELL_UNSUPPORTED_CHECK));
|
|
84
|
-
exports->Set(NewString("LZMA_TELL_ANY_CHECK"), Nan::New<Number>(LZMA_TELL_ANY_CHECK));
|
|
85
|
-
exports->Set(NewString("LZMA_CONCATENATED"), Nan::New<Number>(LZMA_CONCATENATED));
|
|
86
|
-
exports->Set(NewString("LZMA_STREAM_HEADER_SIZE"), Nan::New<Number>(LZMA_STREAM_HEADER_SIZE));
|
|
87
|
-
exports->Set(NewString("LZMA_VERSION_MAJOR"), Nan::New<Number>(LZMA_VERSION_MAJOR));
|
|
88
|
-
exports->Set(NewString("LZMA_VERSION_MINOR"), Nan::New<Number>(LZMA_VERSION_MINOR));
|
|
89
|
-
exports->Set(NewString("LZMA_VERSION_PATCH"), Nan::New<Number>(LZMA_VERSION_PATCH));
|
|
90
|
-
exports->Set(NewString("LZMA_VERSION_STABILITY"), Nan::New<Number>(LZMA_VERSION_STABILITY));
|
|
91
|
-
exports->Set(NewString("LZMA_VERSION_STABILITY_ALPHA"), Nan::New<Number>(LZMA_VERSION_STABILITY_ALPHA));
|
|
92
|
-
exports->Set(NewString("LZMA_VERSION_STABILITY_BETA"), Nan::New<Number>(LZMA_VERSION_STABILITY_BETA));
|
|
93
|
-
exports->Set(NewString("LZMA_VERSION_STABILITY_STABLE"), Nan::New<Number>(LZMA_VERSION_STABILITY_STABLE));
|
|
94
|
-
exports->Set(NewString("LZMA_VERSION"), Nan::New<Number>(LZMA_VERSION));
|
|
95
|
-
exports->Set(NewString("LZMA_VERSION_STRING"), NewString(LZMA_VERSION_STRING));
|
|
96
|
-
|
|
97
|
-
// LZMAStream flags
|
|
98
|
-
exports->Set(NewString("STREAM_ENCODE"), Nan::New<Number>(STREAM_ENCODE));
|
|
99
|
-
exports->Set(NewString("STREAM_DECODE"), Nan::New<Number>(STREAM_DECODE));
|
|
100
|
-
#ifdef LIBLZMA_ENABLE_MT
|
|
101
|
-
exports->Set(NewString("STREAM_ENCODE_MT"), Nan::New<Number>(STREAM_ENCODE_MT));
|
|
102
|
-
#endif
|
|
103
|
-
|
|
104
|
-
exports->Set(NewString("BUFSIZ"), Nan::New<Number>(BUFSIZ));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
NODE_MODULE(node_liblzma, moduleInit)
|
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* node-liblzma - Node.js bindings for liblzma
|
|
3
|
-
* Copyright (C) 2014-2015 Olivier Orabona <olivier.orabona@gmail.com>
|
|
4
|
-
*
|
|
5
|
-
* This program is free software: you can redistribute it and/or modify
|
|
6
|
-
* it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
* (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This program is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
* GNU General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
-
**/
|
|
18
|
-
|
|
19
|
-
#include "node-liblzma.hpp"
|
|
20
|
-
#include <node_buffer.h>
|
|
21
|
-
|
|
22
|
-
using namespace v8;
|
|
23
|
-
|
|
24
|
-
Nan::Persistent<Function> LZMA::constructor;
|
|
25
|
-
|
|
26
|
-
#define LZMA_FETCH_SELF() \
|
|
27
|
-
LZMA* self = NULL; \
|
|
28
|
-
if (!info.This().IsEmpty() && info.This()->InternalFieldCount() > 0) { \
|
|
29
|
-
self = Nan::ObjectWrap::Unwrap<LZMA>(info.This()); \
|
|
30
|
-
} \
|
|
31
|
-
if (!self) { \
|
|
32
|
-
_failMissingSelf(info); \
|
|
33
|
-
return; \
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
void LZMA::Close() {
|
|
37
|
-
if(_wip) {
|
|
38
|
-
_pending_close = true;
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
_pending_close = false;
|
|
43
|
-
|
|
44
|
-
lzma_end(&_stream);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
void LZMA::Init(Local<Object> exports) {
|
|
48
|
-
// constructor template
|
|
49
|
-
Local<FunctionTemplate> t = Nan::New<FunctionTemplate>(New);
|
|
50
|
-
t->InstanceTemplate()->SetInternalFieldCount(1);
|
|
51
|
-
t->SetClassName(NewString("LZMA"));
|
|
52
|
-
|
|
53
|
-
// prototype methods
|
|
54
|
-
t->PrototypeTemplate()->Set(NewString("close"), Nan::New<FunctionTemplate>(Close));
|
|
55
|
-
t->PrototypeTemplate()->Set(NewString("code"), Nan::New<FunctionTemplate>(Code<true>));
|
|
56
|
-
t->PrototypeTemplate()->Set(NewString("codeSync"), Nan::New<FunctionTemplate>(Code<false>));
|
|
57
|
-
|
|
58
|
-
constructor.Reset(t->GetFunction());
|
|
59
|
-
exports->Set(NewString("LZMA"), Nan::New<Function>(constructor));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
NAN_METHOD(LZMA::New) {
|
|
63
|
-
Nan::HandleScope scope;
|
|
64
|
-
if (!info.IsConstructCall()) {
|
|
65
|
-
// Invoked as plain function, turn into construct call.
|
|
66
|
-
info.GetReturnValue().Set(Nan::New<Function>(constructor)->NewInstance(0, NULL));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if( info.Length() != 2 ) {
|
|
70
|
-
Nan::ThrowTypeError(NewString("Wrong number of arguments, expected mode(int) and opts(object)"));
|
|
71
|
-
info.GetReturnValue().SetUndefined();
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
uint32_t mode = info[0]->Uint32Value();
|
|
76
|
-
|
|
77
|
-
if (!info[1]->IsObject()) {
|
|
78
|
-
Nan::ThrowTypeError(NewString("Expected object as second argument"));
|
|
79
|
-
info.GetReturnValue().SetUndefined();
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
Local<Object> opts = info[1]->ToObject();
|
|
84
|
-
lzma_check check = static_cast<lzma_check>(opts->Get(NewString("check"))->Uint32Value());
|
|
85
|
-
uint32_t preset = opts->Get(NewString("preset"))->Uint32Value();
|
|
86
|
-
Local<Array> filters_handle = Local<Array>::Cast(opts->Get(NewString("filters")));
|
|
87
|
-
|
|
88
|
-
uint32_t filters_len = filters_handle->Length();
|
|
89
|
-
|
|
90
|
-
// We will need to add LZMA_VLI_UNKNOWN after, so user defined filters may
|
|
91
|
-
// not exceed LZMA_FILTERS_MAX - 1.
|
|
92
|
-
if( filters_len > LZMA_FILTERS_MAX - 1) {
|
|
93
|
-
Nan::ThrowRangeError(NewString("More filters than allowed maximum"));
|
|
94
|
-
info.GetReturnValue().SetUndefined();
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
lzma_options_lzma opt_lzma2;
|
|
99
|
-
if( lzma_lzma_preset(&opt_lzma2, preset) ) {
|
|
100
|
-
Nan::ThrowError(NewString("Unsupported preset, possibly a bug"));
|
|
101
|
-
info.GetReturnValue().SetUndefined();
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Add extra slot for LZMA_VLI_UNKNOWN.
|
|
106
|
-
lzma_filter filters[filters_len+1];
|
|
107
|
-
|
|
108
|
-
for(uint32_t i = 0; i < filters_len; ++i) {
|
|
109
|
-
uint64_t current = filters_handle->Get(Nan::New<Integer>(i))->Uint32Value();
|
|
110
|
-
filters[i].id = current;
|
|
111
|
-
if( current == LZMA_FILTER_LZMA2 ) {
|
|
112
|
-
filters[i].options = &opt_lzma2;
|
|
113
|
-
} else {
|
|
114
|
-
filters[i].options = NULL;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
filters[filters_len] = { .id = LZMA_VLI_UNKNOWN, .options = NULL };
|
|
119
|
-
|
|
120
|
-
LZMA *self = new LZMA();
|
|
121
|
-
|
|
122
|
-
if (!self) {
|
|
123
|
-
Nan::ThrowRangeError("Out of memory, cannot create LZMAStream");
|
|
124
|
-
info.GetReturnValue().SetUndefined();
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
lzma_ret ret;
|
|
129
|
-
switch(mode) {
|
|
130
|
-
case STREAM_DECODE: {
|
|
131
|
-
ret = lzma_stream_decoder(&self->_stream, UINT64_MAX, check);
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
case STREAM_ENCODE: {
|
|
135
|
-
ret = lzma_stream_encoder(&self->_stream, filters, check);
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
#ifdef LIBLZMA_ENABLE_MT
|
|
139
|
-
case STREAM_ENCODE_MT: {
|
|
140
|
-
unsigned int threads = opts->Get(NewString("threads"))->Uint32Value();
|
|
141
|
-
lzma_mt mt = {
|
|
142
|
-
.flags = 0,
|
|
143
|
-
.threads = threads,
|
|
144
|
-
.block_size = 0,
|
|
145
|
-
.timeout = 0,
|
|
146
|
-
.preset = preset,
|
|
147
|
-
.filters = filters,
|
|
148
|
-
.check = check,
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
ret = lzma_stream_encoder_mt(&self->_stream, &mt);
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
#endif
|
|
155
|
-
default:
|
|
156
|
-
ret = LZMA_OPTIONS_ERROR;
|
|
157
|
-
}
|
|
158
|
-
if (ret != LZMA_OK) {
|
|
159
|
-
delete self;
|
|
160
|
-
info.GetReturnValue().Set(Nan::New<Integer>(ret));
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
self->Wrap(info.This());
|
|
165
|
-
Nan::AdjustExternalMemory(sizeof(LZMA));
|
|
166
|
-
|
|
167
|
-
info.GetReturnValue().Set(info.This());
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
NAN_METHOD(LZMA::Close) {
|
|
171
|
-
LZMA_FETCH_SELF();
|
|
172
|
-
self->Close();
|
|
173
|
-
info.GetReturnValue().SetUndefined();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**<
|
|
177
|
-
* \brief Do the encoding/decoding with async support
|
|
178
|
-
*
|
|
179
|
-
* Function prototype is (sync):
|
|
180
|
-
* .codeSync flushFlag, input_buffer, input_offset, output_buffer, output_offset, callback
|
|
181
|
-
* Function prototype is (async):
|
|
182
|
-
* .code flushFlag, input_buffer, input_offset, availInBefore, output_buffer, output_offset, callback
|
|
183
|
-
*
|
|
184
|
-
* Where:
|
|
185
|
-
* flushFlag: type: Uint32
|
|
186
|
-
* input_buffer: type: Buffer
|
|
187
|
-
* input_offset: type: Uint32
|
|
188
|
-
* availInBefore: type: Uint32
|
|
189
|
-
* output_buffer: type: Buffer
|
|
190
|
-
* output_offset: type: Uint32
|
|
191
|
-
* callback: type: Function
|
|
192
|
-
*/
|
|
193
|
-
template<bool async>
|
|
194
|
-
NAN_METHOD(LZMA::Code) {
|
|
195
|
-
LZMA_FETCH_SELF();
|
|
196
|
-
Nan::HandleScope scope;
|
|
197
|
-
|
|
198
|
-
self->_wip = true;
|
|
199
|
-
self->Ref();
|
|
200
|
-
|
|
201
|
-
// Neat trick but that does the job :)
|
|
202
|
-
if (info.Length() != 6+(int)async) {
|
|
203
|
-
Nan::ThrowError(NewString("BUG?: LZMA::Code requires all these arguments: "
|
|
204
|
-
"flushFlag, input_buffer, input_offset, availInBefore, "
|
|
205
|
-
"output_buffer, output_offset, [callback]"));
|
|
206
|
-
info.GetReturnValue().SetUndefined();
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
self->_action = (lzma_action)info[0]->Uint32Value();
|
|
210
|
-
|
|
211
|
-
// Evaluate parameters passed to us
|
|
212
|
-
const uint8_t *in;
|
|
213
|
-
uint8_t *out;
|
|
214
|
-
size_t in_off, in_len, out_off, out_len;
|
|
215
|
-
|
|
216
|
-
// If we do not have input buffer data
|
|
217
|
-
if (info[1]->IsNull()) {
|
|
218
|
-
// just a flush
|
|
219
|
-
uint8_t nada[1] = { 0 };
|
|
220
|
-
in = nada;
|
|
221
|
-
in_len = 0;
|
|
222
|
-
in_off = 0;
|
|
223
|
-
} else {
|
|
224
|
-
if (!node::Buffer::HasInstance(info[1])) {
|
|
225
|
-
Nan::ThrowTypeError(NewString("BUG?: LZMA::Code 'input_buffer' argument must be a Buffer"));
|
|
226
|
-
info.GetReturnValue().SetUndefined();
|
|
227
|
-
}
|
|
228
|
-
Local<Object> in_buf;
|
|
229
|
-
in_buf = info[1]->ToObject();
|
|
230
|
-
in_off = info[2]->Uint32Value();
|
|
231
|
-
in_len = info[3]->Uint32Value();
|
|
232
|
-
|
|
233
|
-
if(!node::Buffer::IsWithinBounds(in_off, in_len, node::Buffer::Length(in_buf))) {
|
|
234
|
-
Nan::ThrowRangeError(NewString("Offset out of bounds!"));
|
|
235
|
-
info.GetReturnValue().SetUndefined();
|
|
236
|
-
}
|
|
237
|
-
in = reinterpret_cast<const uint8_t *>(node::Buffer::Data(in_buf) + in_off);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// Check if output buffer is also a Buffer
|
|
241
|
-
Local<Object> out_buf = info[4]->ToObject();
|
|
242
|
-
if( !node::Buffer::HasInstance(out_buf) ) {
|
|
243
|
-
Nan::ThrowTypeError(NewString("BUG?: LZMA::Code 'output_buffer' argument must be a Buffer"));
|
|
244
|
-
info.GetReturnValue().SetUndefined();
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
out_off = info[5]->Uint32Value();
|
|
248
|
-
out_len = node::Buffer::Length(out_buf) - out_off;
|
|
249
|
-
out = reinterpret_cast<uint8_t *>(node::Buffer::Data(out_buf) + out_off);
|
|
250
|
-
|
|
251
|
-
// Only if async mode is enabled shall we need a callback function
|
|
252
|
-
if(async)
|
|
253
|
-
self->_callback.SetFunction(info[6].As<Function>());
|
|
254
|
-
|
|
255
|
-
self->_stream.next_in = in;
|
|
256
|
-
self->_stream.avail_in = in_len;
|
|
257
|
-
self->_stream.next_out = out;
|
|
258
|
-
self->_stream.avail_out = out_len;
|
|
259
|
-
|
|
260
|
-
// make us reference ourselves because of how async work_req event loop structure works
|
|
261
|
-
self->_req.data = self;
|
|
262
|
-
|
|
263
|
-
// do it synchronously
|
|
264
|
-
if(!async) {
|
|
265
|
-
Process(&(self->_req));
|
|
266
|
-
info.GetReturnValue().Set(AfterSync(self));
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// otherwise queue work, make sure we get our work done by first calling Process and then After
|
|
271
|
-
uv_queue_work(uv_default_loop(), &(self->_req), LZMA::Process, LZMA::After);
|
|
272
|
-
info.GetReturnValue().SetUndefined();
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
void LZMA::Process(uv_work_t* work_req) {
|
|
277
|
-
LZMA* obj = static_cast<LZMA*>(work_req->data);
|
|
278
|
-
|
|
279
|
-
// the real work is done here :)
|
|
280
|
-
obj->_wip = true;
|
|
281
|
-
obj->_ret = lzma_code(&(obj->_stream), obj->_action);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
void LZMA::After(uv_work_t* work_req, int status) {
|
|
285
|
-
Nan::HandleScope scope;
|
|
286
|
-
LZMA* obj = static_cast<LZMA*>(work_req->data);
|
|
287
|
-
|
|
288
|
-
Local<Number> ret_code = Nan::New<Number>(obj->_ret);
|
|
289
|
-
Local<Number> avail_in = Nan::New<Number>(obj->_stream.avail_in);
|
|
290
|
-
Local<Number> avail_out = Nan::New<Number>(obj->_stream.avail_out);
|
|
291
|
-
Local<Value> argv[3] = { ret_code, avail_in, avail_out };
|
|
292
|
-
|
|
293
|
-
obj->_wip = false;
|
|
294
|
-
|
|
295
|
-
obj->_callback.Call(ARRAY_SIZE(argv), argv);
|
|
296
|
-
|
|
297
|
-
obj->Unref();
|
|
298
|
-
if(obj->_pending_close) {
|
|
299
|
-
obj->Close();
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
Local<Value> LZMA::AfterSync(LZMA* obj) {
|
|
304
|
-
Local<Number> ret_code = Nan::New<Number>(obj->_ret);
|
|
305
|
-
Local<Number> avail_in = Nan::New<Number>(obj->_stream.avail_in);
|
|
306
|
-
Local<Number> avail_out = Nan::New<Number>(obj->_stream.avail_out);
|
|
307
|
-
Local<Array> result = Nan::New<Array>(3);
|
|
308
|
-
result->Set(0, ret_code);
|
|
309
|
-
result->Set(1, avail_in);
|
|
310
|
-
result->Set(2, avail_out);
|
|
311
|
-
|
|
312
|
-
obj->_wip = false;
|
|
313
|
-
|
|
314
|
-
obj->Unref();
|
|
315
|
-
if(obj->_pending_close) {
|
|
316
|
-
obj->Close();
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return result;
|
|
320
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* node-liblzma - Node.js bindings for liblzma
|
|
3
|
-
* Copyright (C) 2014-2015 Olivier Orabona <olivier.orabona@gmail.com>
|
|
4
|
-
*
|
|
5
|
-
* This program is free software: you can redistribute it and/or modify
|
|
6
|
-
* it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
* (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This program is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
* GNU General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
-
**/
|
|
18
|
-
|
|
19
|
-
#ifndef BUILDING_NODE_EXTENSION
|
|
20
|
-
#define BUILDING_NODE_EXTENSION
|
|
21
|
-
#endif
|
|
22
|
-
|
|
23
|
-
#ifndef NODE_LIBLZMA_H
|
|
24
|
-
# define NODE_LIBLZMA_H
|
|
25
|
-
|
|
26
|
-
#include <node.h>
|
|
27
|
-
#include <node_object_wrap.h>
|
|
28
|
-
#include <v8.h>
|
|
29
|
-
#include <nan.h>
|
|
30
|
-
|
|
31
|
-
using v8::Array;
|
|
32
|
-
using v8::Context;
|
|
33
|
-
using v8::Function;
|
|
34
|
-
using v8::FunctionTemplate;
|
|
35
|
-
using v8::Handle;
|
|
36
|
-
using v8::Local;
|
|
37
|
-
using v8::Object;
|
|
38
|
-
using v8::Persistent;
|
|
39
|
-
using v8::String;
|
|
40
|
-
using v8::Value;
|
|
41
|
-
|
|
42
|
-
#include <sstream>
|
|
43
|
-
|
|
44
|
-
#ifdef LIBLZMA_ENABLE_MT
|
|
45
|
-
# warning "Building with (unstable) multithread support"
|
|
46
|
-
# define LZMA_UNSTABLE
|
|
47
|
-
#endif
|
|
48
|
-
#include <lzma.h>
|
|
49
|
-
|
|
50
|
-
#define STREAM_ENCODE 0
|
|
51
|
-
#define STREAM_DECODE 1
|
|
52
|
-
#define STREAM_ENCODE_MT 2
|
|
53
|
-
|
|
54
|
-
#define CONST_UINT32(target, value) \
|
|
55
|
-
target->Set(String::NewSymbol(#value), Uint32::New(value), \
|
|
56
|
-
static_cast<PropertyAttribute>(ReadOnly|DontDelete));
|
|
57
|
-
|
|
58
|
-
#ifndef ARRAY_SIZE
|
|
59
|
-
# define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
|
60
|
-
#endif
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Create a new v8 String
|
|
64
|
-
*/
|
|
65
|
-
template<typename T>
|
|
66
|
-
inline Local<String> NewString(T value) {
|
|
67
|
-
return Nan::New<String>(value).ToLocalChecked();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
class LZMA : public Nan::ObjectWrap {
|
|
71
|
-
public:
|
|
72
|
-
static void Init(Local<Object> exports);
|
|
73
|
-
|
|
74
|
-
private:
|
|
75
|
-
explicit LZMA() : ObjectWrap(), _stream(LZMA_STREAM_INIT),
|
|
76
|
-
_wip(false), _pending_close(false)
|
|
77
|
-
{
|
|
78
|
-
}
|
|
79
|
-
~LZMA() {
|
|
80
|
-
Nan::AdjustExternalMemory(-int64_t(sizeof(LZMA)));
|
|
81
|
-
Close();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
void Close();
|
|
85
|
-
|
|
86
|
-
static NAN_METHOD(New);
|
|
87
|
-
static NAN_METHOD(Close);
|
|
88
|
-
|
|
89
|
-
template<bool async>
|
|
90
|
-
static NAN_METHOD(Code);
|
|
91
|
-
|
|
92
|
-
private:
|
|
93
|
-
static void Process(uv_work_t* work_req);
|
|
94
|
-
static void After(uv_work_t* work_req, int status);
|
|
95
|
-
static Local<Value> AfterSync(LZMA* obj);
|
|
96
|
-
|
|
97
|
-
static Nan::Persistent<Function> constructor;
|
|
98
|
-
|
|
99
|
-
static void _failMissingSelf(const Nan::FunctionCallbackInfo<Value>& info) {
|
|
100
|
-
Nan::ThrowTypeError("LZMA methods need to be called on an LZMA object");
|
|
101
|
-
info.GetReturnValue().SetUndefined();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
uv_work_t _req;
|
|
105
|
-
|
|
106
|
-
lzma_stream _stream;
|
|
107
|
-
bool _wip;
|
|
108
|
-
bool _pending_close;
|
|
109
|
-
|
|
110
|
-
lzma_action _action;
|
|
111
|
-
Nan::Callback _callback;
|
|
112
|
-
lzma_ret _ret;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
#endif // NODE_LIBLZMA_H
|