node-liblzma 1.1.7 → 1.1.8

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/lib/lzma.js CHANGED
@@ -1,384 +1,381 @@
1
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);
2
+ /*
3
+ * node-liblzma - Node.js bindings for liblzma
4
+ * Copyright (C) Olivier Orabona <olivier.orabona@gmail.com>
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Lesser General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public License
17
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
+ */
19
+ var Transform, Unxz, Xz, XzStream, assert, binding_path, liblzma, maxThreads, os, path, util, xzBuffer, xzBufferSync;
20
+
21
+ path = require('path');
22
+
23
+ binding_path = path.resolve(path.join(__dirname, '..'));
24
+
25
+ liblzma = require('node-gyp-build')(binding_path);
26
+
27
+ util = require('util');
28
+
29
+ assert = require('assert');
30
+
31
+ os = require('os');
32
+
33
+ ({Transform} = require('stream'));
34
+
35
+ // Should not change over time... :)
36
+ maxThreads = os.cpus().length;
37
+
38
+ XzStream = class XzStream extends Transform {
39
+ constructor(mode, _opts = {}, options) {
40
+ var base, base1, base2, base3, base4;
41
+ super(options);
42
+ this._opts = _opts;
43
+ if ((base = this._opts).check == null) {
44
+ base.check = exports.check.NONE;
94
45
  }
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];
46
+ if ((base1 = this._opts).preset == null) {
47
+ base1.preset = exports.preset.DEFAULT;
48
+ }
49
+ if ((base2 = this._opts).filters == null) {
50
+ base2.filters = [exports.filter.LZMA2];
51
+ }
52
+ if ((base3 = this._opts).mode == null) {
53
+ base3.mode = exports.mode.NORMAL;
54
+ }
55
+ if ((base4 = this._opts).threads == null) {
56
+ base4.threads = 1;
57
+ }
58
+ this._chunkSize = this._opts.chunkSize ? this._opts.chunkSize : liblzma.BUFSIZ;
59
+ // By default no flush, since there is no LZMA_NO_SYNC, we stick to
60
+ // default LZMA_RUN (0)
61
+ this._flushFlag = this._opts.flushFlag || liblzma.LZMA_RUN;
62
+ assert(Array.isArray(this._opts.filters), "Filters need to be in an array!");
63
+ // Add default filter LZMA2 if none provided
64
+ if (this._opts.filters.indexOf(exports.filter.LZMA2) === -1) {
65
+ this._opts.filters.push(exports.filter.LZMA2);
66
+ }
67
+ // Multithreading is only available for encoding, so if we are encoding, check
68
+ // opts threads value.
69
+ if (mode === liblzma.STREAM_ENCODE) {
70
+ if (!liblzma.HAS_THREADS_SUPPORT) {
71
+ this._opts.threads = 1;
101
72
  }
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);
73
+ // By default set to maximum available processors
74
+ if (this._opts.threads === 0) {
75
+ this._opts.threads = maxThreads;
117
76
  }
118
77
  }
119
-
120
- close(callback) {
78
+ // Initialize engine
79
+ this.lzma = new liblzma.LZMA(mode, this._opts);
80
+ this._closed = false;
81
+ this._hadError = false;
82
+ this._offset = 0;
83
+ this._buffer = Buffer.alloc(this._chunkSize);
84
+ this.on('onerror', (errno) => {
85
+ var error;
86
+ this._hadError = true;
87
+ error = new Error(exports.messages[errno]);
88
+ error.errno = errno;
89
+ error.code = errno;
90
+ return this.emit('error', error);
91
+ });
92
+ this.once('end', this.close);
93
+ }
94
+
95
+ flush(kind, callback) {
96
+ var ws;
97
+ ws = this._writableState;
98
+ if (typeof kind === 'function' || (typeof kind === 'undefined' && !callback)) {
99
+ [callback, kind] = [kind, liblzma.LZMA_SYNC_FLUSH];
100
+ }
101
+ if (ws.ended) {
121
102
  if (callback) {
122
103
  process.nextTick(callback);
123
104
  }
124
- // We will trigger this case with #xz and #unxz
125
- if (this._closed) {
126
- return;
105
+ } else if (ws.ending) {
106
+ if (callback) {
107
+ this.once('end', callback);
127
108
  }
128
- this.lzma.close();
129
- this._closed = true;
130
- process.nextTick(() => {
131
- this.emit('close');
109
+ } else if (ws.needDrain) {
110
+ this.once('drain', () => {
111
+ this.flush(callback);
132
112
  });
113
+ } else {
114
+ this._flushFlag = kind;
115
+ this.write(Buffer.alloc(0), '', callback);
133
116
  }
117
+ }
134
118
 
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"));
119
+ close(callback) {
120
+ if (callback) {
121
+ process.nextTick(callback);
122
+ }
123
+ // We will trigger this case with #xz and #unxz
124
+ if (this._closed) {
125
+ return;
126
+ }
127
+ this.lzma.close();
128
+ this._closed = true;
129
+ process.nextTick(() => {
130
+ this.emit('close');
131
+ });
132
+ }
133
+
134
+ _transform(chunk, encoding, callback) {
135
+ var ending, flushFlag, last, ws;
136
+ flushFlag = void 0;
137
+ ws = this._writableState;
138
+ ending = ws.ending || ws.ended;
139
+ last = ending && (!chunk || ws.length === chunk.length);
140
+ if (chunk !== null && !(chunk instanceof Buffer)) {
141
+ return callback(new Error("invalid input"));
142
+ }
143
+ if (this._closed) {
144
+ return callback(new Error("lzma binding closed"));
145
+ }
146
+ // If it's the last chunk, or a final flush, we use the LZMA_FINISH flush flag.
147
+ // If it's explicitly flushing at some other time, then we use
148
+ // LZMA_SYNC_FLUSH.
149
+ if (last) {
150
+ flushFlag = liblzma.LZMA_FINISH;
151
+ } else {
152
+ flushFlag = this._flushFlag;
153
+ if (chunk.length >= ws.length) {
154
+ // once we've flushed the last of the queue, stop flushing and
155
+ // go back to the normal behavior.
156
+ this._flushFlag = this._opts.flushFlag || liblzma.LZMA_RUN;
143
157
  }
144
- if (this._closed) {
145
- return callback(new Error("lzma binding closed"));
158
+ }
159
+ this._processChunk(chunk, flushFlag, callback);
160
+ }
161
+
162
+ _flush(callback) {
163
+ this._transform(Buffer.alloc(0), '', callback);
164
+ }
165
+
166
+ _processChunk(chunk, flushFlag, cb) {
167
+ var async, availInBefore, availOutBefore, buf, buffers, callback, error, inOff, nread, res;
168
+ // If user setting async is set to true, then it will all depend on whether
169
+ // we can actually be async, or not. If user set explicitly async to false
170
+ // then whether we have a callback or not becomes irrelevant..
171
+ // TODO: Works in v0.11
172
+ //async = util.isFunction cb
173
+ // until then...
174
+ async = typeof cb === 'function';
175
+ // Sanity checks
176
+ assert(!this._closed, "Stream closed!");
177
+ availInBefore = chunk && chunk.length;
178
+ availOutBefore = this._chunkSize - this._offset;
179
+ inOff = 0;
180
+ // So far it looks like Zlib _processChunk in CoffeeScript. But to make C++
181
+ // code easier when it comes to emitting events and callback calling sync/async
182
+ // we handle error codes here. If anything wrong is returned, we emit event
183
+ // and return false in case we are synchronous.
184
+ callback = (errno, availInAfter, availOutAfter) => {
185
+ var out, used;
186
+ if (this._hadError) {
187
+ return;
146
188
  }
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
- }
189
+ // if LZMA engine returned something else, we are running into trouble!
190
+ if (errno !== liblzma.LZMA_OK && errno !== liblzma.LZMA_STREAM_END) {
191
+ this.emit('onerror', errno);
192
+ return false;
159
193
  }
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;
194
+ used = availOutBefore - availOutAfter;
195
+ assert(used >= 0, `More bytes after than before! Delta = ${used}`);
196
+ if (used > 0) {
197
+ out = this._buffer.slice(this._offset, this._offset + used);
198
+ this._offset += used;
199
+ if (async) {
200
+ this.push(out);
201
+ } else {
202
+ buffers.push(out);
203
+ nread += used;
221
204
  }
205
+ }
206
+ // exhausted the output buffer, or used all the input create a new one.
207
+ if (availOutAfter === 0 || this._offset >= this._chunkSize) {
208
+ availOutBefore = this._chunkSize;
209
+ this._offset = 0;
210
+ this._buffer = Buffer.alloc(this._chunkSize);
211
+ }
212
+ if (availOutAfter === 0 || availInAfter > 0) {
213
+ inOff += availInBefore - availInAfter;
214
+ availInBefore = availInAfter;
222
215
  if (!async) {
223
- return false;
216
+ return true;
224
217
  }
225
- cb();
226
- };
218
+ this.lzma.code(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset, callback);
219
+ return;
220
+ }
227
221
  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;
222
+ return false;
223
+ }
224
+ cb();
225
+ };
226
+ if (!async) {
227
+ // Doing it synchronously
228
+ buffers = [];
229
+ nread = 0;
230
+ error = null;
231
+ this.on('error', function(e) {
232
+ return error = e;
233
+ });
234
+ while (true) {
235
+ res = this.lzma.codeSync(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset);
236
+ if (!(!this._hadError && callback(res[0], res[1], res[2]))) {
237
+ break;
243
238
  }
244
- this.close();
245
- buf = Buffer.concat(buffers, nread);
246
- return buf;
247
239
  }
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, {}];
240
+ if (this._hadError) {
241
+ throw error;
242
+ }
243
+ this.close();
244
+ buf = Buffer.concat(buffers, nread);
245
+ return buf;
322
246
  }
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, {}];
247
+ this.lzma.code(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset, callback);
248
+ }
249
+
250
+ };
251
+
252
+ Xz = class Xz extends XzStream {
253
+ constructor(lzma_options, options) {
254
+ super(liblzma.STREAM_ENCODE, lzma_options, options);
255
+ }
256
+
257
+ };
258
+
259
+ Unxz = class Unxz extends XzStream {
260
+ constructor(lzma_options, options) {
261
+ super(liblzma.STREAM_DECODE, lzma_options, options);
262
+ }
263
+
264
+ };
265
+
266
+ exports.Xz = Xz;
267
+
268
+ exports.Unxz = Unxz;
269
+
270
+ exports.hasThreads = function() {
271
+ return liblzma.HAS_THREADS_SUPPORT;
272
+ };
273
+
274
+ 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"];
275
+
276
+ exports.check = {
277
+ "NONE": liblzma.LZMA_CHECK_NONE,
278
+ "CRC32": liblzma.LZMA_CHECK_CRC32,
279
+ "CRC64": liblzma.LZMA_CHECK_CRC64,
280
+ "SHA256": liblzma.LZMA_CHECK_SHA256
281
+ };
282
+
283
+ exports.preset = {
284
+ "DEFAULT": liblzma.LZMA_PRESET_DEFAULT,
285
+ "EXTREME": liblzma.LZMA_PRESET_EXTREME
286
+ };
287
+
288
+ exports.flag = {
289
+ "TELL_NO_CHECK": liblzma.LZMA_TELL_NO_CHECK,
290
+ "TELL_UNSUPPORTED_CHECK": liblzma.LZMA_TELL_UNSUPPORTED_CHECK,
291
+ "TELL_ANY_CHECK": liblzma.LZMA_TELL_ANY_CHECK,
292
+ "CONCATENATED": liblzma.LZMA_CONCATENATED
293
+ };
294
+
295
+ exports.filter = {
296
+ "LZMA2": liblzma.LZMA_FILTER_LZMA2,
297
+ "X86": liblzma.LZMA_FILTER_X86,
298
+ "POWERPC": liblzma.LZMA_FILTER_POWERPC,
299
+ "IA64": liblzma.LZMA_FILTER_IA64,
300
+ "ARM": liblzma.LZMA_FILTER_ARM,
301
+ "ARMTHUMB": liblzma.LZMA_FILTER_ARMTHUMB,
302
+ "SPARC": liblzma.LZMA_FILTER_SPARC
303
+ };
304
+
305
+ exports.mode = {
306
+ "FAST": liblzma.LZMA_MODE_FAST,
307
+ "NORMAL": liblzma.LZMA_MODE_NORMAL
308
+ };
309
+
310
+ exports.createXz = function(lzma_options, options) {
311
+ return new Xz(lzma_options, options);
312
+ };
313
+
314
+ exports.createUnxz = function(lzma_options, options) {
315
+ return new Unxz(lzma_options, options);
316
+ };
317
+
318
+ exports.unxz = function(buffer, opts, callback) {
319
+ if (typeof opts === 'function') {
320
+ [callback, opts] = [opts, {}];
321
+ }
322
+ return xzBuffer(new Unxz(opts), buffer, callback);
323
+ };
324
+
325
+ exports.unxzSync = function(buffer, opts) {
326
+ return xzBufferSync(new Unxz(opts), buffer);
327
+ };
328
+
329
+ exports.xz = function(buffer, opts, callback) {
330
+ if (typeof opts === 'function') {
331
+ [callback, opts] = [opts, {}];
332
+ }
333
+ return xzBuffer(new Xz(opts), buffer, callback);
334
+ };
335
+
336
+ exports.xzSync = function(buffer, opts) {
337
+ return xzBufferSync(new Xz(opts), buffer);
338
+ };
339
+
340
+ xzBuffer = function(engine, buffer, callback) {
341
+ var buffers, flow, nread, onEnd, onError;
342
+ buffers = [];
343
+ nread = 0;
344
+ flow = function() {
345
+ var chunk;
346
+ chunk = void 0;
347
+ while (null !== (chunk = engine.read())) {
348
+ buffers.push(chunk);
349
+ nread += chunk.length;
333
350
  }
334
- return xzBuffer(new Xz(opts), buffer, callback);
335
- };
336
-
337
- exports.xzSync = function(buffer, opts) {
338
- return xzBufferSync(new Xz(opts), buffer);
351
+ engine.once('readable', flow);
339
352
  };
340
-
341
- xzBuffer = function(engine, buffer, callback) {
342
- var buffers, flow, nread, onEnd, onError;
353
+ onEnd = function() {
354
+ var buf;
355
+ buf = Buffer.concat(buffers, nread);
343
356
  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();
357
+ callback(null, buf);
358
+ engine.close();
370
359
  };
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);
360
+ onError = function(err) {
361
+ engine.removeListener('end', onEnd);
362
+ engine.removeListener('readable', flow);
363
+ callback(err);
380
364
  };
381
-
382
- module.exports = exports;
383
-
384
- }).call(this);
365
+ engine.on('error', onError);
366
+ engine.on('end', onEnd);
367
+ engine.end(buffer);
368
+ flow();
369
+ };
370
+
371
+ xzBufferSync = function(engine, buffer) {
372
+ if (typeof buffer === 'string') {
373
+ buffer = Buffer.from(buffer);
374
+ }
375
+ if (!(buffer instanceof Buffer)) {
376
+ throw new TypeError("Not a string or buffer");
377
+ }
378
+ return engine._processChunk(buffer, liblzma.LZMA_FINISH);
379
+ };
380
+
381
+ module.exports = exports;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "node-liblzma",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "NodeJS wrapper for liblzma",
5
5
  "main": "./lib/lzma.js",
6
6
  "scripts": {
7
7
  "install": "node-gyp-build",
8
- "prepare": "npx ynpx coffeescript --compile --output lib/ src/",
8
+ "prepare": "npx ynpx coffeescript --bare --compile --output lib/ src/",
9
9
  "prebuildify": "npx prebuildify --napi --strip -t $(node -v)",
10
10
  "prebuildify:win": "for /f \"usebackq tokens=*\" %v in (`node -v`) do npx prebuildify -t %v --napi --strip",
11
11
  "test": "mocha test/*.coffee"
Binary file
Binary file