node-liblzma 1.0.4-8 → 1.1.4

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.
@@ -1,115 +1,87 @@
1
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
- **/
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
18
 
19
19
  #ifndef BUILDING_NODE_EXTENSION
20
20
  #define BUILDING_NODE_EXTENSION
21
21
  #endif
22
22
 
23
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;
24
+ #define NODE_LIBLZMA_H
41
25
 
42
- #include <sstream>
43
-
44
- #ifdef LIBLZMA_ENABLE_MT
45
- # warning "Building with (unstable) multithread support"
46
- # define LZMA_UNSTABLE
47
- #endif
48
26
  #include <lzma.h>
27
+ #include <napi.h>
49
28
 
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));
29
+ #include <sstream>
57
30
 
58
- #ifndef ARRAY_SIZE
59
- # define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
60
- #endif
31
+ constexpr unsigned int STREAM_ENCODE = 0;
32
+ constexpr unsigned int STREAM_DECODE = 1;
33
+ constexpr unsigned int STREAM_ENCODE_MT = 2;
61
34
 
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 {
35
+ class LZMAWorker;
36
+ class LZMA : public Napi::ObjectWrap<LZMA> {
71
37
  public:
72
- static void Init(Local<Object> exports);
38
+ static void Init(Napi::Env env, Napi::Object exports);
73
39
 
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
- }
40
+ explicit LZMA(const Napi::CallbackInfo& info);
41
+ ~LZMA() = default;
83
42
 
84
- void Close();
43
+ Napi::Value Close(const Napi::CallbackInfo &info);
44
+ Napi::Value Close(const Napi::Env &env);
85
45
 
86
- static NAN_METHOD(New);
87
- static NAN_METHOD(Close);
46
+ template<bool async>
47
+ Napi::Value Code(const Napi::CallbackInfo &info);
88
48
 
89
- template<bool async>
90
- static NAN_METHOD(Code);
49
+ static void Process(LZMA* obj);
50
+ static void After(Napi::Env env, LZMA* obj /*, int status */);
51
+ static Napi::Value AfterSync(const Napi::CallbackInfo &info, LZMA* obj);
91
52
 
92
53
  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;
54
+ lzma_stream _stream;
55
+ bool _wip;
56
+ bool _pending_close;
98
57
 
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
- }
58
+ LZMAWorker* _worker;
103
59
 
104
- uv_work_t _req;
105
-
106
- lzma_stream _stream;
107
- bool _wip;
108
- bool _pending_close;
60
+ lzma_action _action;
61
+ Napi::FunctionReference _callback;
62
+ lzma_ret _ret;
63
+ lzma_filter *filters;
64
+ };
109
65
 
110
- lzma_action _action;
111
- Nan::Callback _callback;
112
- lzma_ret _ret;
66
+ class LZMAWorker : public Napi::AsyncWorker {
67
+ public:
68
+ LZMAWorker(Napi::Env env, LZMA* instance) : AsyncWorker(env), lzma(instance) { }
69
+ ~LZMAWorker() = default;
70
+
71
+ void Execute() {
72
+ LZMA::Process(this->lzma);
73
+ }
74
+ void OnOK() {
75
+ Napi::HandleScope scope(Env());
76
+ LZMA::After(Env(), this->lzma);
77
+ }
78
+ void OnError(const Napi::Error& e) {
79
+ Napi::HandleScope scope(Env());
80
+ LZMA::After(Env(), this->lzma);
81
+ }
82
+
83
+ private:
84
+ LZMA *lzma;
113
85
  };
114
86
 
115
87
  #endif // NODE_LIBLZMA_H
package/src/lzma.coffee CHANGED
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  * node-liblzma - Node.js bindings for liblzma
3
- * Copyright (C) 2014-2015 Olivier Orabona <olivier.orabona@gmail.com>
3
+ * Copyright (C) Olivier Orabona <olivier.orabona@gmail.com>
4
4
  *
5
5
  * This program is free software: you can redistribute it and/or modify
6
6
  * it under the terms of the GNU Lesser General Public License as published by
@@ -16,8 +16,10 @@
16
16
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
17
  ###
18
18
 
19
- liblzma = require '../build/Release/node-liblzma.node'
19
+ path = require 'path'
20
+ binding_path = path.resolve path.join __dirname, '..'
20
21
 
22
+ liblzma = require('node-gyp-build')(binding_path)
21
23
  util = require 'util'
22
24
  assert = require 'assert'
23
25
  os = require 'os'
@@ -64,7 +66,7 @@ class XzStream extends Transform
64
66
  @_closed = false
65
67
  @_hadError = false
66
68
  @_offset = 0
67
- @_buffer = new Buffer @_chunkSize
69
+ @_buffer = Buffer.alloc @_chunkSize
68
70
 
69
71
  @on 'onerror', (errno) =>
70
72
  @_hadError = true
@@ -77,7 +79,7 @@ class XzStream extends Transform
77
79
  @once 'end', @close
78
80
 
79
81
  flush: (kind, callback) ->
80
- ws = @_writableState;
82
+ ws = @_writableState
81
83
 
82
84
  if (typeof kind == 'function' or (typeof kind == 'undefined' && !callback))
83
85
  [callback, kind] = [kind, liblzma.LZMA_SYNC_FLUSH]
@@ -94,7 +96,7 @@ class XzStream extends Transform
94
96
  return
95
97
  else
96
98
  @_flushFlag = kind
97
- @write new Buffer(0), '', callback
99
+ @write Buffer.alloc(0), '', callback
98
100
 
99
101
  return
100
102
 
@@ -119,8 +121,8 @@ class XzStream extends Transform
119
121
  ws = @_writableState
120
122
  ending = ws.ending or ws.ended
121
123
  last = ending and (not chunk or ws.length is chunk.length)
122
- return callback(new Error("invalid input")) if chunk != null and !(chunk instanceof Buffer)
123
- return callback(new Error("lzma binding closed")) if @_closed
124
+ return callback(new Error("invalid input")) if chunk != null and !(chunk instanceof Buffer)
125
+ return callback(new Error("lzma binding closed")) if @_closed
124
126
 
125
127
  # If it's the last chunk, or a final flush, we use the LZMA_FINISH flush flag.
126
128
  # If it's explicitly flushing at some other time, then we use
@@ -132,13 +134,13 @@ class XzStream extends Transform
132
134
 
133
135
  # once we've flushed the last of the queue, stop flushing and
134
136
  # go back to the normal behavior.
135
- @_flushFlag = @_opts.flushFlag or liblzma.LZMA_RUN if chunk.length >= ws.length
137
+ @_flushFlag = @_opts.flushFlag or liblzma.LZMA_RUN if chunk.length >= ws.length
136
138
 
137
139
  @_processChunk chunk, flushFlag, callback
138
140
  return
139
141
 
140
142
  _flush: (callback) ->
141
- @_transform new Buffer(0), '', callback
143
+ @_transform Buffer.alloc(0), '', callback
142
144
  return
143
145
 
144
146
  _processChunk: (chunk, flushFlag, cb) ->
@@ -173,7 +175,7 @@ class XzStream extends Transform
173
175
  assert used >= 0, "More bytes after than before! Delta = #{used}"
174
176
 
175
177
  if used > 0
176
- out = @_buffer[@_offset...@_offset+used]
178
+ out = @_buffer[ @_offset ... @_offset + used ]
177
179
  @_offset += used
178
180
  if async
179
181
  @push out
@@ -185,7 +187,7 @@ class XzStream extends Transform
185
187
  if availOutAfter is 0 or @_offset >= @_chunkSize
186
188
  availOutBefore = @_chunkSize
187
189
  @_offset = 0
188
- @_buffer = new Buffer @_chunkSize
190
+ @_buffer = Buffer.alloc @_chunkSize
189
191
 
190
192
  if availOutAfter is 0 or availInAfter > 0
191
193
  inOff += (availInBefore - availInAfter)
@@ -251,23 +253,26 @@ exports.messages = [
251
253
  "Programming error"
252
254
  ]
253
255
 
254
- exports.check =
256
+ exports.check = {
255
257
  "NONE": liblzma.LZMA_CHECK_NONE
256
258
  "CRC32": liblzma.LZMA_CHECK_CRC32
257
259
  "CRC64": liblzma.LZMA_CHECK_CRC64
258
260
  "SHA256": liblzma.LZMA_CHECK_SHA256
261
+ }
259
262
 
260
- exports.preset =
263
+ exports.preset = {
261
264
  "DEFAULT": liblzma.LZMA_PRESET_DEFAULT
262
265
  "EXTREME": liblzma.LZMA_PRESET_EXTREME
266
+ }
263
267
 
264
- exports.flag =
268
+ exports.flag = {
265
269
  "TELL_NO_CHECK": liblzma.LZMA_TELL_NO_CHECK
266
270
  "TELL_UNSUPPORTED_CHECK": liblzma.LZMA_TELL_UNSUPPORTED_CHECK
267
271
  "TELL_ANY_CHECK": liblzma.LZMA_TELL_ANY_CHECK
268
272
  "CONCATENATED": liblzma.LZMA_CONCATENATED
273
+ }
269
274
 
270
- exports.filter =
275
+ exports.filter = {
271
276
  "LZMA2": liblzma.LZMA_FILTER_LZMA2
272
277
  "X86": liblzma.LZMA_FILTER_X86
273
278
  "POWERPC": liblzma.LZMA_FILTER_POWERPC
@@ -275,10 +280,12 @@ exports.filter =
275
280
  "ARM": liblzma.LZMA_FILTER_ARM
276
281
  "ARMTHUMB": liblzma.LZMA_FILTER_ARMTHUMB
277
282
  "SPARC": liblzma.LZMA_FILTER_SPARC
283
+ }
278
284
 
279
- exports.mode =
285
+ exports.mode = {
280
286
  "FAST": liblzma.LZMA_MODE_FAST
281
287
  "NORMAL": liblzma.LZMA_MODE_NORMAL
288
+ }
282
289
 
283
290
  exports.createXz = (lzma_options, options) ->
284
291
  new Xz(lzma_options, options)
@@ -331,8 +338,8 @@ xzBuffer = (engine, buffer, callback) ->
331
338
  return
332
339
 
333
340
  xzBufferSync = (engine, buffer) ->
334
- buffer = new Buffer(buffer) if typeof buffer == 'string'
335
- throw new TypeError("Not a string or buffer") unless buffer instanceof Buffer
341
+ buffer = Buffer.from(buffer) if typeof buffer == 'string'
342
+ throw new TypeError("Not a string or buffer") unless buffer instanceof Buffer
336
343
 
337
344
  engine._processChunk buffer, liblzma.LZMA_FINISH
338
345
 
package/build.yml DELETED
@@ -1,78 +0,0 @@
1
- init:
2
- plugins:
3
- - mocha
4
- - clean
5
- - packagejson
6
- - grab
7
- settings:
8
- exec:
9
- env:
10
- CPPFLAGS: "-fPIC"
11
- CFLAGS: "-O3"
12
- xzWebUrl: 'http://tukaani.org/xz/xz'
13
- xzVersion: '5.2.2'
14
- xzExt: 'gz'
15
- clean:
16
- path: ['lib', '*.log']
17
- distclean: ['build', 'xz*.tar.*']
18
- srcPath: 'src'
19
- libPath: 'lib'
20
- coffee: './node_modules/.bin/coffee'
21
- npg: './node_modules/.bin/node-pre-gyp'
22
- cpu: 4
23
- mocha:
24
- useCoffee: true
25
- clean:
26
- - '%npg% clean'
27
- - rm -rf %clean.path%
28
- fetch_lzma:
29
- - log: Fetching source ...
30
- - grab: "%xzWebUrl%-%xzVersion%.tar.%xzExt%"
31
- - mkdir -p deps/xz
32
- - '[ "%xzExt%" = "gz" ] && tar zxvf xz-%xzVersion%.tar.%xzExt% -C deps/xz --strip-components=1'
33
- - '[ "%xzExt%" = "bz2" ] && tar jxvf xz-%xzVersion%.tar.%xzExt% -C deps/xz --strip-components=1'
34
- - '[ "%xzExt%" = "xz" ] && tar Jxvf xz-%xzVersion%.tar.%xzExt% -C deps/xz --strip-components=1'
35
- build_lzma:
36
- - log: Building LibLZMA from sources, using %cpu% threads ! (change by passing cpu=xxx)
37
- - log: Cleaning deps ...
38
- - rm -rf deps
39
- - task: fetch_lzma
40
- - cd deps/xz
41
- - ./autogen.sh
42
- - ./configure --prefix=`pwd` --enable-threads --enable-static --disable-shared --disable-scripts --disable-lzmainfo
43
- --disable-lzma-links --disable-lzmadec --disable-xzdec --disable-xz --disable-rpath
44
- - make -j%cpu%
45
- - make install
46
- - env: CPATH=`pwd`/include
47
- - env: LIBRARY_PATH=`pwd`/lib
48
- - env: LD_LIBRARY_PATH=$LIBRARY_PATH:$LD_LIBRARY_PATH
49
- - log: Done compiling liblzma. headers are at $CPATH
50
- - cd ../..
51
- build_module:
52
- - log: Building %name% version %version% Add-On ...
53
- - '%npg% configure build'
54
- install_module:
55
- - log: Installing %name% version %version Add-On ...
56
- - '%npg% install --fallback-to-build'
57
- build:
58
- # If we are compiling, we surely won't want to try to download a precompiled binary
59
- - |
60
- if [ "$COMPILE" = "1" ]
61
- then
62
- %ubs% build_lzma build_module xzVersion=%xzVersion% xzExt=%xzExt%
63
- else
64
- %ubs% install_module
65
- fi
66
- # If we do not have any js file, we build it
67
- - '[ -r %libPath%/lzma.js ] || %ubs% build_coffee'
68
- build_coffee:
69
- - log: Building Javascript API...
70
- - '%coffee% -b -c -o %libPath% %srcPath%'
71
- - log: Done building Javascript.
72
- test:
73
- # Make sure we have our devDependencies with us.
74
- - npm i
75
- - task: mocha-test
76
- install:
77
- - task: build
78
- - log: Build done.