node-liblzma 1.1.9 → 2.0.0

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.
Files changed (76) hide show
  1. package/.claude/settings.local.json +92 -0
  2. package/.gitattributes +3 -0
  3. package/.release-it.json +6 -0
  4. package/CHANGELOG.md +209 -0
  5. package/History.md +20 -0
  6. package/README.md +750 -30
  7. package/RELEASING.md +131 -0
  8. package/binding.gyp +159 -438
  9. package/biome.json +81 -0
  10. package/coverage/base.css +224 -0
  11. package/coverage/block-navigation.js +87 -0
  12. package/coverage/errors.ts.html +586 -0
  13. package/coverage/favicon.png +0 -0
  14. package/coverage/index.html +146 -0
  15. package/coverage/lcov-report/base.css +224 -0
  16. package/coverage/lcov-report/block-navigation.js +87 -0
  17. package/coverage/lcov-report/errors.ts.html +586 -0
  18. package/coverage/lcov-report/favicon.png +0 -0
  19. package/coverage/lcov-report/index.html +146 -0
  20. package/coverage/lcov-report/lzma.ts.html +2596 -0
  21. package/coverage/lcov-report/pool.ts.html +769 -0
  22. package/coverage/lcov-report/prettify.css +1 -0
  23. package/coverage/lcov-report/prettify.js +2 -0
  24. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  25. package/coverage/lcov-report/sorter.js +210 -0
  26. package/coverage/lcov.info +636 -0
  27. package/coverage/lzma.ts.html +2596 -0
  28. package/coverage/pool.ts.html +769 -0
  29. package/coverage/prettify.css +1 -0
  30. package/coverage/prettify.js +2 -0
  31. package/coverage/sort-arrow-sprite.png +0 -0
  32. package/coverage/sorter.js +210 -0
  33. package/coverage-reports/assets/monocart-coverage-app.js +2 -0
  34. package/coverage-reports/coverage-data.js +1 -0
  35. package/coverage-reports/index.html +48 -0
  36. package/err.log +26 -0
  37. package/index.d.ts +254 -0
  38. package/lib/errors.d.ts +72 -0
  39. package/lib/errors.d.ts.map +1 -0
  40. package/lib/errors.js +153 -0
  41. package/lib/errors.js.map +1 -0
  42. package/lib/lzma.d.ts +245 -0
  43. package/lib/lzma.d.ts.map +1 -0
  44. package/lib/lzma.js +626 -345
  45. package/lib/lzma.js.map +1 -0
  46. package/lib/pool.d.ts +123 -0
  47. package/lib/pool.d.ts.map +1 -0
  48. package/lib/pool.js +188 -0
  49. package/lib/pool.js.map +1 -0
  50. package/lib/types.d.ts +27 -0
  51. package/lib/types.d.ts.map +1 -0
  52. package/lib/types.js +5 -0
  53. package/lib/types.js.map +1 -0
  54. package/package.json +60 -21
  55. package/pnpm-workspace.yaml +3 -0
  56. package/scripts/analyze-coverage.js +132 -0
  57. package/scripts/build_xz_with_cmake.py +390 -0
  58. package/scripts/compare-coverage-tools.js +93 -0
  59. package/scripts/copy_dll.py +51 -0
  60. package/scripts/download_xz_from_github.py +375 -0
  61. package/src/bindings/node-liblzma.cpp +411 -229
  62. package/src/bindings/node-liblzma.hpp +101 -48
  63. package/src/errors.ts +167 -0
  64. package/src/lzma.ts +839 -0
  65. package/src/pool.ts +228 -0
  66. package/src/types.ts +30 -0
  67. package/tsconfig.json +50 -0
  68. package/vitest.config.istanbul.ts +29 -0
  69. package/vitest.config.monocart.ts +44 -0
  70. package/vitest.config.ts +44 -0
  71. package/xz-version.json +8 -0
  72. package/prebuilds/darwin-x64/node.napi.node +0 -0
  73. package/prebuilds/linux-x64/node.napi.node +0 -0
  74. package/prebuilds/win32-x64/node.napi.node +0 -0
  75. package/scripts/download_extract_deps.py +0 -29
  76. package/src/lzma.coffee +0 -344
package/src/lzma.coffee DELETED
@@ -1,344 +0,0 @@
1
- ###
2
- * node-liblzma - Node.js bindings for liblzma
3
- * Copyright (C) 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
- path = require 'path'
20
- binding_path = path.resolve path.join __dirname, '..'
21
-
22
- liblzma = require('node-gyp-build')(binding_path)
23
- util = require 'util'
24
- assert = require 'assert'
25
- os = require 'os'
26
- { Transform } = require 'stream'
27
-
28
- # Should not change over time... :)
29
- maxThreads = os.cpus().length
30
-
31
- class XzStream extends Transform
32
- constructor: (mode, @_opts = {}, options) ->
33
- super options
34
-
35
- @_opts.check ?= exports.check.NONE
36
- @_opts.preset ?= exports.preset.DEFAULT
37
- @_opts.filters ?= [exports.filter.LZMA2]
38
- @_opts.mode ?= exports.mode.NORMAL
39
- @_opts.threads ?= 1
40
-
41
- @_chunkSize = if @_opts.chunkSize then @_opts.chunkSize else liblzma.BUFSIZ
42
-
43
- # By default no flush, since there is no LZMA_NO_SYNC, we stick to
44
- # default LZMA_RUN (0)
45
- @_flushFlag = @_opts.flushFlag or liblzma.LZMA_RUN
46
-
47
- assert Array.isArray(@_opts.filters), "Filters need to be in an array!"
48
-
49
- # Add default filter LZMA2 if none provided
50
- if @_opts.filters.indexOf(exports.filter.LZMA2) is -1
51
- @_opts.filters.push exports.filter.LZMA2
52
-
53
- # Multithreading is only available for encoding, so if we are encoding, check
54
- # opts threads value.
55
- if mode is liblzma.STREAM_ENCODE
56
- @_opts.threads = 1 unless liblzma.HAS_THREADS_SUPPORT
57
-
58
- # By default set to maximum available processors
59
- if @_opts.threads is 0
60
- @_opts.threads = maxThreads
61
-
62
- # Initialize engine
63
- @lzma = new liblzma.LZMA mode, @_opts
64
- @_closed = false
65
- @_hadError = false
66
- @_offset = 0
67
- @_buffer = Buffer.alloc @_chunkSize
68
-
69
- @on 'onerror', (errno) =>
70
- @_hadError = true
71
- error = new Error exports.messages[errno]
72
- error.errno = errno
73
- error.code = errno
74
-
75
- @emit 'error', error
76
-
77
- @once 'end', @close
78
-
79
- flush: (kind, callback) ->
80
- ws = @_writableState
81
-
82
- if (typeof kind == 'function' or (typeof kind == 'undefined' && !callback))
83
- [callback, kind] = [kind, liblzma.LZMA_SYNC_FLUSH]
84
-
85
- if ws.ended
86
- if callback
87
- process.nextTick callback
88
- else if ws.ending
89
- if callback
90
- @once 'end', callback
91
- else if ws.needDrain
92
- @once 'drain', =>
93
- @flush callback
94
- return
95
- else
96
- @_flushFlag = kind
97
- @write Buffer.alloc(0), '', callback
98
-
99
- return
100
-
101
- close: (callback) ->
102
- if callback
103
- process.nextTick callback
104
-
105
- # We will trigger this case with #xz and #unxz
106
- return if @_closed
107
-
108
- @lzma.close()
109
- @_closed = true
110
-
111
- process.nextTick =>
112
- @emit 'close'
113
- return
114
-
115
- return
116
-
117
- _transform: (chunk, encoding, callback) ->
118
- flushFlag = undefined
119
- ws = @_writableState
120
- ending = ws.ending or ws.ended
121
- 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
-
125
- # If it's the last chunk, or a final flush, we use the LZMA_FINISH flush flag.
126
- # If it's explicitly flushing at some other time, then we use
127
- # LZMA_SYNC_FLUSH.
128
- if last
129
- flushFlag = liblzma.LZMA_FINISH
130
- else
131
- flushFlag = @_flushFlag
132
-
133
- # once we've flushed the last of the queue, stop flushing and
134
- # go back to the normal behavior.
135
- @_flushFlag = @_opts.flushFlag or liblzma.LZMA_RUN if chunk.length >= ws.length
136
-
137
- @_processChunk chunk, flushFlag, callback
138
- return
139
-
140
- _flush: (callback) ->
141
- @_transform Buffer.alloc(0), '', callback
142
- return
143
-
144
- _processChunk: (chunk, flushFlag, cb) ->
145
- # If user setting async is set to true, then it will all depend on whether
146
- # we can actually be async, or not. If user set explicitly async to false
147
- # then whether we have a callback or not becomes irrelevant..
148
- # TODO: Works in v0.11
149
- #async = util.isFunction cb
150
- # until then...
151
- async = typeof cb == 'function'
152
-
153
- # Sanity checks
154
- assert !@_closed, "Stream closed!"
155
-
156
- availInBefore = chunk && chunk.length
157
- availOutBefore = @_chunkSize - @_offset
158
- inOff = 0
159
-
160
- # So far it looks like Zlib _processChunk in CoffeeScript. But to make C++
161
- # code easier when it comes to emitting events and callback calling sync/async
162
- # we handle error codes here. If anything wrong is returned, we emit event
163
- # and return false in case we are synchronous.
164
- callback = (errno, availInAfter, availOutAfter) =>
165
- return if @_hadError
166
-
167
- # if LZMA engine returned something else, we are running into trouble!
168
- if errno isnt liblzma.LZMA_OK and errno isnt liblzma.LZMA_STREAM_END
169
- @emit 'onerror', errno
170
- return false
171
-
172
- used = availOutBefore - availOutAfter
173
- assert used >= 0, "More bytes after than before! Delta = #{used}"
174
-
175
- if used > 0
176
- out = @_buffer[ @_offset ... @_offset + used ]
177
- @_offset += used
178
- if async
179
- @push out
180
- else
181
- buffers.push out
182
- nread += used
183
-
184
- # exhausted the output buffer, or used all the input create a new one.
185
- if availOutAfter is 0 or @_offset >= @_chunkSize
186
- availOutBefore = @_chunkSize
187
- @_offset = 0
188
- @_buffer = Buffer.alloc @_chunkSize
189
-
190
- if availOutAfter is 0 or availInAfter > 0
191
- inOff += (availInBefore - availInAfter)
192
- availInBefore = availInAfter
193
-
194
- return true unless async
195
- @lzma.code flushFlag, chunk, inOff, availInBefore, @_buffer, @_offset, callback
196
- return
197
-
198
- return false unless async
199
- cb()
200
- return
201
-
202
- unless async
203
- # Doing it synchronously
204
- buffers = []
205
- nread = 0
206
-
207
- error = null
208
- @on 'error', (e) -> error = e
209
-
210
- loop
211
- res = @lzma.codeSync flushFlag, chunk, inOff, availInBefore, @_buffer, @_offset
212
- break unless not @_hadError and callback res[0], res[1], res[2]
213
-
214
- throw error if @_hadError
215
- @close()
216
-
217
- buf = Buffer.concat buffers, nread
218
- return buf
219
-
220
- @lzma.code flushFlag, chunk, inOff, availInBefore, @_buffer, @_offset, callback
221
-
222
- return
223
-
224
- class Xz extends XzStream
225
- constructor: (lzma_options, options) ->
226
- super liblzma.STREAM_ENCODE, lzma_options, options
227
-
228
- class Unxz extends XzStream
229
- constructor: (lzma_options, options) ->
230
- super liblzma.STREAM_DECODE, lzma_options, options
231
-
232
-
233
- exports.Xz = Xz
234
- exports.Unxz = Unxz
235
-
236
- exports.hasThreads = ->
237
- liblzma.HAS_THREADS_SUPPORT
238
-
239
- exports.messages = [
240
- "Operation completed successfully"
241
- "End of stream was reached"
242
- "Input stream has no integrity check"
243
- "Cannot calculate the integrity check"
244
- "Integrity check type is not available"
245
- "Cannot allocate memory"
246
- "Memory usage limit was reached"
247
- "File format not recognized"
248
- "Invalid or unsupported options"
249
- "Data is corrupt"
250
- "No progress is possible"
251
- "Programming error"
252
- ]
253
-
254
- exports.check = {
255
- "NONE": liblzma.LZMA_CHECK_NONE
256
- "CRC32": liblzma.LZMA_CHECK_CRC32
257
- "CRC64": liblzma.LZMA_CHECK_CRC64
258
- "SHA256": liblzma.LZMA_CHECK_SHA256
259
- }
260
-
261
- exports.preset = {
262
- "DEFAULT": liblzma.LZMA_PRESET_DEFAULT
263
- "EXTREME": liblzma.LZMA_PRESET_EXTREME
264
- }
265
-
266
- exports.flag = {
267
- "TELL_NO_CHECK": liblzma.LZMA_TELL_NO_CHECK
268
- "TELL_UNSUPPORTED_CHECK": liblzma.LZMA_TELL_UNSUPPORTED_CHECK
269
- "TELL_ANY_CHECK": liblzma.LZMA_TELL_ANY_CHECK
270
- "CONCATENATED": liblzma.LZMA_CONCATENATED
271
- }
272
-
273
- exports.filter = {
274
- "LZMA2": liblzma.LZMA_FILTER_LZMA2
275
- "X86": liblzma.LZMA_FILTER_X86
276
- "POWERPC": liblzma.LZMA_FILTER_POWERPC
277
- "IA64": liblzma.LZMA_FILTER_IA64
278
- "ARM": liblzma.LZMA_FILTER_ARM
279
- "ARMTHUMB": liblzma.LZMA_FILTER_ARMTHUMB
280
- "SPARC": liblzma.LZMA_FILTER_SPARC
281
- }
282
-
283
- exports.mode = {
284
- "FAST": liblzma.LZMA_MODE_FAST
285
- "NORMAL": liblzma.LZMA_MODE_NORMAL
286
- }
287
-
288
- exports.createXz = (lzma_options, options) ->
289
- new Xz(lzma_options, options)
290
-
291
- exports.createUnxz = (lzma_options, options) ->
292
- new Unxz(lzma_options, options)
293
-
294
- exports.unxz = (buffer, opts, callback) ->
295
- if typeof opts == 'function'
296
- [callback, opts] = [opts, {}]
297
-
298
- xzBuffer new Unxz(opts), buffer, callback
299
-
300
- exports.unxzSync = (buffer, opts) ->
301
- xzBufferSync new Unxz(opts), buffer
302
-
303
- exports.xz = (buffer, opts, callback) ->
304
- if typeof opts == 'function'
305
- [callback, opts] = [opts, {}]
306
- xzBuffer new Xz(opts), buffer, callback
307
-
308
- exports.xzSync = (buffer, opts) ->
309
- xzBufferSync new Xz(opts), buffer
310
-
311
- xzBuffer = (engine, buffer, callback) ->
312
- buffers = []
313
- nread = 0
314
- flow = ->
315
- chunk = undefined
316
- while null isnt (chunk = engine.read())
317
- buffers.push chunk
318
- nread += chunk.length
319
- engine.once 'readable', flow
320
- return
321
- onEnd = ->
322
- buf = Buffer.concat(buffers, nread)
323
- buffers = []
324
- callback null, buf
325
- engine.close()
326
- return
327
- onError = (err) ->
328
- engine.removeListener 'end', onEnd
329
- engine.removeListener 'readable', flow
330
- callback err
331
- return
332
- engine.on 'error', onError
333
- engine.on 'end', onEnd
334
- engine.end buffer
335
- flow()
336
- return
337
-
338
- xzBufferSync = (engine, buffer) ->
339
- buffer = Buffer.from(buffer) if typeof buffer == 'string'
340
- throw new TypeError("Not a string or buffer") unless buffer instanceof Buffer
341
-
342
- engine._processChunk buffer, liblzma.LZMA_FINISH
343
-
344
- module.exports = exports