@ohos-ports/electron-internal-extract-zip 1.0.5-beta.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.
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # @electron-internal/extract-zip
2
+
3
+ > [!WARNING]
4
+ > **Internal to the Electron project.** This package exists to serve Electron's
5
+ > own tooling. Use from non-Electron packages is not supported: the API may
6
+ > change to suit Electron's needs, and bug reports or feature requests from
7
+ > outside use cases may be closed without action. If you need a general-purpose
8
+ > extractor, use [`extract-zip`](https://github.com/max-mapper/extract-zip).
9
+
10
+ Fast, safe, native zip extraction for Node.js. Drop-in replacement for [`extract-zip`](https://github.com/max-mapper/extract-zip).
11
+
12
+ - **Native**: Rust core via N-API, decompression runs off the event loop.
13
+ - **Fast**: ~2x faster on entry-heavy archives, never slower. See [benchmarks](#benchmarks).
14
+ - **Safe**: hardened against Zip Slip, symlink escapes, absolute paths, NUL injection, Windows reserved names, and zip bombs.
15
+ - **Zero runtime deps**: no `debug`/`yauzl`/`get-stream` in your tree.
16
+ - **Cross-platform**: prebuilt binaries for macOS, Linux (glibc/musl), and Windows (x64/arm64).
17
+
18
+ ## Install
19
+
20
+ ```sh
21
+ yarn add @electron-internal/extract-zip
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ESM only:
27
+
28
+ ```js
29
+ import extract from '@electron-internal/extract-zip';
30
+
31
+ await extract('archive.zip', { dir: '/absolute/output/path' });
32
+ ```
33
+
34
+ `dir` (required, absolute) is the only option. Everything else is fixed: existing
35
+ files are overwritten, archive mode bits (masked to `0o777`) and mtimes are
36
+ preserved, symlinks are created (skipped on Windows without symlink privilege),
37
+ and writes are parallelised across `min(cpus, 8)` workers. The original's
38
+ `onEntry`, `defaultDirMode`, and `defaultFileMode` are not supported, since no
39
+ consumer in the `electron` org uses them.
40
+
41
+ ## Security
42
+
43
+ This package is hardened for extracting trusted Electron distribution archives,
44
+ enforcing path containment against Zip Slip, symlink escapes, absolute paths, NUL
45
+ injection, Windows reserved names, and zip bombs. Its threat model and the full
46
+ list of containment guarantees are documented in [`SECURITY.md`](./SECURITY.md).
47
+
48
+ Extracting untrusted or unverified archives is out of scope — see
49
+ [`SECURITY.md`](./SECURITY.md) for details.
50
+
51
+ ## Benchmarks
52
+
53
+ `yarn bench` (Apple M-series, Node 24, median of 5):
54
+
55
+ | Corpus | Zip size | `extract-zip` (JS) | this | Speedup |
56
+ |---|--:|--:|--:|--:|
57
+ | electron-v42.2.0-darwin-arm64 | 112 MB | 817 ms | 441 ms | 1.9x |
58
+ | 8 x 4 MB compressible | 0.1 MB | 24 ms | 3 ms | 9.4x |
59
+ | 2000 small text files | 0.4 MB | 372 ms | 199 ms | 1.9x |
60
+ | 200 incompressible files | 6.2 MB | 40 ms | 22 ms | 1.8x |
61
+ | `node_modules` | 2.9 MB | 68 ms | 37 ms | 1.9x |
62
+
63
+ Extraction runs in phases: validate paths and create directories, inflate and
64
+ write files in parallel with zlib-ng, then apply symlinks and directory
65
+ metadata. The Electron number is gated by its single 182 MB framework binary,
66
+ which can't be split further.
67
+
68
+ ## Distribution
69
+
70
+ One package ships all prebuilt binaries (~2 MB gzipped): macOS
71
+ `darwin-universal`, Windows `x64`/`arm64`, and Linux `x64`/`arm64` for both glibc
72
+ and musl. `binding.js` picks the right one at load time. No
73
+ `optionalDependencies`, no postinstall, no network at install.
74
+
75
+ ## Building from source
76
+
77
+ Requires a Rust toolchain (and `cmake` for zlib-ng).
78
+
79
+ ```sh
80
+ yarn install
81
+ yarn build # builds index.<your-platform>.node
82
+ yarn test
83
+ ```
84
+
85
+ ## Releasing
86
+
87
+ Releases are driven by [semantic-release](https://semantic-release.gitbook.io/)
88
+ on every push to `main`: conventional commit messages decide the version bump,
89
+ CI builds all targets, and the fat package is published to npm via trusted
90
+ publishing. No manual version bumps or tags.
91
+
92
+ ## License
93
+
94
+ BSD-2-Clause
package/binding.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ export declare function extract(zipPath: string, opts: ExtractOptions): Promise<void>
4
+
5
+ export interface ExtractOptions {
6
+ /** Destination directory. Must be an absolute path. */
7
+ dir: string
8
+ }
package/binding.js ADDED
@@ -0,0 +1,629 @@
1
+ // prettier-ignore
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ import { createRequire } from 'node:module'
7
+ const require = createRequire(import.meta.url)
8
+ const __dirname = new URL('.', import.meta.url).pathname
9
+
10
+ const { readFileSync } = require('node:fs')
11
+ let nativeBinding = null
12
+ const loadErrors = []
13
+
14
+ const isMusl = () => {
15
+ let musl = false
16
+ if (process.platform === 'linux') {
17
+ musl = isMuslFromFilesystem()
18
+ if (musl === null) {
19
+ musl = isMuslFromReport()
20
+ }
21
+ if (musl === null) {
22
+ musl = isMuslFromChildProcess()
23
+ }
24
+ }
25
+ return musl
26
+ }
27
+
28
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
29
+
30
+ const isMuslFromFilesystem = () => {
31
+ try {
32
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
33
+ } catch {
34
+ return null
35
+ }
36
+ }
37
+
38
+ const isMuslFromReport = () => {
39
+ let report = null
40
+ if (typeof process.report?.getReport === 'function') {
41
+ process.report.excludeNetwork = true
42
+ report = process.report.getReport()
43
+ }
44
+ if (!report) {
45
+ return null
46
+ }
47
+ if (report.header && report.header.glibcVersionRuntime) {
48
+ return false
49
+ }
50
+ if (Array.isArray(report.sharedObjects)) {
51
+ if (report.sharedObjects.some(isFileMusl)) {
52
+ return true
53
+ }
54
+ }
55
+ return false
56
+ }
57
+
58
+ const isMuslFromChildProcess = () => {
59
+ try {
60
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
61
+ } catch (e) {
62
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
63
+ return false
64
+ }
65
+ }
66
+
67
+ function requireNative() {
68
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
69
+ try {
70
+ return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
71
+ } catch (err) {
72
+ loadErrors.push(err)
73
+ }
74
+ } else if (process.platform === 'android') {
75
+ if (process.arch === 'arm64') {
76
+ try {
77
+ return require('./index.android-arm64.node')
78
+ } catch (e) {
79
+ loadErrors.push(e)
80
+ }
81
+ try {
82
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-android-arm64 is intentionally not published)') })()
83
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-android-arm64/package.json is intentionally not published)') })().version
84
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
85
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
86
+ }
87
+ return binding
88
+ } catch (e) {
89
+ loadErrors.push(e)
90
+ }
91
+ } else if (process.arch === 'arm') {
92
+ try {
93
+ return require('./index.android-arm-eabi.node')
94
+ } catch (e) {
95
+ loadErrors.push(e)
96
+ }
97
+ try {
98
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-android-arm-eabi is intentionally not published)') })()
99
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-android-arm-eabi/package.json is intentionally not published)') })().version
100
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
101
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
102
+ }
103
+ return binding
104
+ } catch (e) {
105
+ loadErrors.push(e)
106
+ }
107
+ } else {
108
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
109
+ }
110
+ } else if (process.platform === 'win32') {
111
+ if (process.arch === 'x64') {
112
+ if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
113
+ try {
114
+ return require('./index.win32-x64-gnu.node')
115
+ } catch (e) {
116
+ loadErrors.push(e)
117
+ }
118
+ try {
119
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-win32-x64-gnu is intentionally not published)') })()
120
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-win32-x64-gnu/package.json is intentionally not published)') })().version
121
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
122
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
123
+ }
124
+ return binding
125
+ } catch (e) {
126
+ loadErrors.push(e)
127
+ }
128
+ } else {
129
+ try {
130
+ return require('./index.win32-x64-msvc.node')
131
+ } catch (e) {
132
+ loadErrors.push(e)
133
+ }
134
+ try {
135
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-win32-x64-msvc is intentionally not published)') })()
136
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-win32-x64-msvc/package.json is intentionally not published)') })().version
137
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
138
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
139
+ }
140
+ return binding
141
+ } catch (e) {
142
+ loadErrors.push(e)
143
+ }
144
+ }
145
+ } else if (process.arch === 'ia32') {
146
+ try {
147
+ return require('./index.win32-ia32-msvc.node')
148
+ } catch (e) {
149
+ loadErrors.push(e)
150
+ }
151
+ try {
152
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-win32-ia32-msvc is intentionally not published)') })()
153
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-win32-ia32-msvc/package.json is intentionally not published)') })().version
154
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
155
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
156
+ }
157
+ return binding
158
+ } catch (e) {
159
+ loadErrors.push(e)
160
+ }
161
+ } else if (process.arch === 'arm64') {
162
+ try {
163
+ return require('./index.win32-arm64-msvc.node')
164
+ } catch (e) {
165
+ loadErrors.push(e)
166
+ }
167
+ try {
168
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-win32-arm64-msvc is intentionally not published)') })()
169
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-win32-arm64-msvc/package.json is intentionally not published)') })().version
170
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
171
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
172
+ }
173
+ return binding
174
+ } catch (e) {
175
+ loadErrors.push(e)
176
+ }
177
+ } else {
178
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
179
+ }
180
+ } else if (process.platform === 'darwin') {
181
+ try {
182
+ return require('./index.darwin-universal.node')
183
+ } catch (e) {
184
+ loadErrors.push(e)
185
+ }
186
+ try {
187
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-darwin-universal is intentionally not published)') })()
188
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-darwin-universal/package.json is intentionally not published)') })().version
189
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
190
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
191
+ }
192
+ return binding
193
+ } catch (e) {
194
+ loadErrors.push(e)
195
+ }
196
+ if (process.arch === 'x64') {
197
+ try {
198
+ return require('./index.darwin-x64.node')
199
+ } catch (e) {
200
+ loadErrors.push(e)
201
+ }
202
+ try {
203
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-darwin-x64 is intentionally not published)') })()
204
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-darwin-x64/package.json is intentionally not published)') })().version
205
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
206
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
207
+ }
208
+ return binding
209
+ } catch (e) {
210
+ loadErrors.push(e)
211
+ }
212
+ } else if (process.arch === 'arm64') {
213
+ try {
214
+ return require('./index.darwin-arm64.node')
215
+ } catch (e) {
216
+ loadErrors.push(e)
217
+ }
218
+ try {
219
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-darwin-arm64 is intentionally not published)') })()
220
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-darwin-arm64/package.json is intentionally not published)') })().version
221
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
222
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
223
+ }
224
+ return binding
225
+ } catch (e) {
226
+ loadErrors.push(e)
227
+ }
228
+ } else {
229
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
230
+ }
231
+ } else if (process.platform === 'freebsd') {
232
+ if (process.arch === 'x64') {
233
+ try {
234
+ return require('./index.freebsd-x64.node')
235
+ } catch (e) {
236
+ loadErrors.push(e)
237
+ }
238
+ try {
239
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-freebsd-x64 is intentionally not published)') })()
240
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-freebsd-x64/package.json is intentionally not published)') })().version
241
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
242
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
243
+ }
244
+ return binding
245
+ } catch (e) {
246
+ loadErrors.push(e)
247
+ }
248
+ } else if (process.arch === 'arm64') {
249
+ try {
250
+ return require('./index.freebsd-arm64.node')
251
+ } catch (e) {
252
+ loadErrors.push(e)
253
+ }
254
+ try {
255
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-freebsd-arm64 is intentionally not published)') })()
256
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-freebsd-arm64/package.json is intentionally not published)') })().version
257
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
258
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
259
+ }
260
+ return binding
261
+ } catch (e) {
262
+ loadErrors.push(e)
263
+ }
264
+ } else {
265
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
266
+ }
267
+ } else if (process.platform === 'linux') {
268
+ if (process.arch === 'x64') {
269
+ if (isMusl()) {
270
+ try {
271
+ return require('./index.linux-x64-musl.node')
272
+ } catch (e) {
273
+ loadErrors.push(e)
274
+ }
275
+ try {
276
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-x64-musl is intentionally not published)') })()
277
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-x64-musl/package.json is intentionally not published)') })().version
278
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
279
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
280
+ }
281
+ return binding
282
+ } catch (e) {
283
+ loadErrors.push(e)
284
+ }
285
+ } else {
286
+ try {
287
+ return require('./index.linux-x64-gnu.node')
288
+ } catch (e) {
289
+ loadErrors.push(e)
290
+ }
291
+ try {
292
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-x64-gnu is intentionally not published)') })()
293
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-x64-gnu/package.json is intentionally not published)') })().version
294
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
295
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
296
+ }
297
+ return binding
298
+ } catch (e) {
299
+ loadErrors.push(e)
300
+ }
301
+ try {
302
+ return require('./index.linux-x64-musl.node')
303
+ } catch (e) {
304
+ loadErrors.push(e)
305
+ }
306
+ try {
307
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-x64-musl is intentionally not published)') })()
308
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-x64-musl/package.json is intentionally not published)') })().version
309
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
310
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
311
+ }
312
+ return binding
313
+ } catch (e) {
314
+ loadErrors.push(e)
315
+ }
316
+ }
317
+ } else if (process.arch === 'arm64') {
318
+ if (isMusl()) {
319
+ try {
320
+ return require('./index.linux-arm64-musl.node')
321
+ } catch (e) {
322
+ loadErrors.push(e)
323
+ }
324
+ try {
325
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-arm64-musl is intentionally not published)') })()
326
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-arm64-musl/package.json is intentionally not published)') })().version
327
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
328
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
329
+ }
330
+ return binding
331
+ } catch (e) {
332
+ loadErrors.push(e)
333
+ }
334
+ } else {
335
+ try {
336
+ return require('./index.linux-arm64-gnu.node')
337
+ } catch (e) {
338
+ loadErrors.push(e)
339
+ }
340
+ try {
341
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-arm64-gnu is intentionally not published)') })()
342
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-arm64-gnu/package.json is intentionally not published)') })().version
343
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
344
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
345
+ }
346
+ return binding
347
+ } catch (e) {
348
+ loadErrors.push(e)
349
+ }
350
+ try {
351
+ return require('./index.linux-arm64-musl.node')
352
+ } catch (e) {
353
+ loadErrors.push(e)
354
+ }
355
+ try {
356
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-arm64-musl is intentionally not published)') })()
357
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-arm64-musl/package.json is intentionally not published)') })().version
358
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
+ }
361
+ return binding
362
+ } catch (e) {
363
+ loadErrors.push(e)
364
+ }
365
+ }
366
+ } else if (process.arch === 'arm') {
367
+ if (isMusl()) {
368
+ try {
369
+ return require('./index.linux-arm-musleabihf.node')
370
+ } catch (e) {
371
+ loadErrors.push(e)
372
+ }
373
+ try {
374
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-arm-musleabihf is intentionally not published)') })()
375
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-arm-musleabihf/package.json is intentionally not published)') })().version
376
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
+ }
379
+ return binding
380
+ } catch (e) {
381
+ loadErrors.push(e)
382
+ }
383
+ } else {
384
+ try {
385
+ return require('./index.linux-arm-gnueabihf.node')
386
+ } catch (e) {
387
+ loadErrors.push(e)
388
+ }
389
+ try {
390
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-arm-gnueabihf is intentionally not published)') })()
391
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-arm-gnueabihf/package.json is intentionally not published)') })().version
392
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
+ }
395
+ return binding
396
+ } catch (e) {
397
+ loadErrors.push(e)
398
+ }
399
+ }
400
+ } else if (process.arch === 'loong64') {
401
+ if (isMusl()) {
402
+ try {
403
+ return require('./index.linux-loong64-musl.node')
404
+ } catch (e) {
405
+ loadErrors.push(e)
406
+ }
407
+ try {
408
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-loong64-musl is intentionally not published)') })()
409
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-loong64-musl/package.json is intentionally not published)') })().version
410
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
+ }
413
+ return binding
414
+ } catch (e) {
415
+ loadErrors.push(e)
416
+ }
417
+ } else {
418
+ try {
419
+ return require('./index.linux-loong64-gnu.node')
420
+ } catch (e) {
421
+ loadErrors.push(e)
422
+ }
423
+ try {
424
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-loong64-gnu is intentionally not published)') })()
425
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-loong64-gnu/package.json is intentionally not published)') })().version
426
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
+ }
429
+ return binding
430
+ } catch (e) {
431
+ loadErrors.push(e)
432
+ }
433
+ }
434
+ } else if (process.arch === 'riscv64') {
435
+ if (isMusl()) {
436
+ try {
437
+ return require('./index.linux-riscv64-musl.node')
438
+ } catch (e) {
439
+ loadErrors.push(e)
440
+ }
441
+ try {
442
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-riscv64-musl is intentionally not published)') })()
443
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-riscv64-musl/package.json is intentionally not published)') })().version
444
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
445
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
446
+ }
447
+ return binding
448
+ } catch (e) {
449
+ loadErrors.push(e)
450
+ }
451
+ } else {
452
+ try {
453
+ return require('./index.linux-riscv64-gnu.node')
454
+ } catch (e) {
455
+ loadErrors.push(e)
456
+ }
457
+ try {
458
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-riscv64-gnu is intentionally not published)') })()
459
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-riscv64-gnu/package.json is intentionally not published)') })().version
460
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
461
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
462
+ }
463
+ return binding
464
+ } catch (e) {
465
+ loadErrors.push(e)
466
+ }
467
+ }
468
+ } else if (process.arch === 'ppc64') {
469
+ try {
470
+ return require('./index.linux-ppc64-gnu.node')
471
+ } catch (e) {
472
+ loadErrors.push(e)
473
+ }
474
+ try {
475
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-ppc64-gnu is intentionally not published)') })()
476
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-ppc64-gnu/package.json is intentionally not published)') })().version
477
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
478
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
479
+ }
480
+ return binding
481
+ } catch (e) {
482
+ loadErrors.push(e)
483
+ }
484
+ } else if (process.arch === 's390x') {
485
+ try {
486
+ return require('./index.linux-s390x-gnu.node')
487
+ } catch (e) {
488
+ loadErrors.push(e)
489
+ }
490
+ try {
491
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-s390x-gnu is intentionally not published)') })()
492
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-s390x-gnu/package.json is intentionally not published)') })().version
493
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
494
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
495
+ }
496
+ return binding
497
+ } catch (e) {
498
+ loadErrors.push(e)
499
+ }
500
+ } else if (process.arch === 'ia32') {
501
+ try {
502
+ return require('./index.linux-ia32-gnu.node')
503
+ } catch (e) {
504
+ loadErrors.push(e)
505
+ }
506
+ try {
507
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-ia32-gnu is intentionally not published)') })()
508
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-linux-ia32-gnu/package.json is intentionally not published)') })().version
509
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
510
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
511
+ }
512
+ return binding
513
+ } catch (e) {
514
+ loadErrors.push(e)
515
+ }
516
+ } else {
517
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
518
+ }
519
+ } else if (process.platform === 'openharmony') {
520
+ if (process.arch === 'arm64') {
521
+ try {
522
+ return require('./index.openharmony-arm64.node')
523
+ } catch (e) {
524
+ loadErrors.push(e)
525
+ }
526
+ try {
527
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-openharmony-arm64 is intentionally not published)') })()
528
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-openharmony-arm64/package.json is intentionally not published)') })().version
529
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
530
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
531
+ }
532
+ return binding
533
+ } catch (e) {
534
+ loadErrors.push(e)
535
+ }
536
+ } else if (process.arch === 'x64') {
537
+ try {
538
+ return require('./index.openharmony-x64.node')
539
+ } catch (e) {
540
+ loadErrors.push(e)
541
+ }
542
+ try {
543
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-openharmony-x64 is intentionally not published)') })()
544
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-openharmony-x64/package.json is intentionally not published)') })().version
545
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
546
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
547
+ }
548
+ return binding
549
+ } catch (e) {
550
+ loadErrors.push(e)
551
+ }
552
+ } else if (process.arch === 'arm') {
553
+ try {
554
+ return require('./index.openharmony-arm.node')
555
+ } catch (e) {
556
+ loadErrors.push(e)
557
+ }
558
+ try {
559
+ const binding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-openharmony-arm is intentionally not published)') })()
560
+ const bindingPackageVersion = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-openharmony-arm/package.json is intentionally not published)') })().version
561
+ if (bindingPackageVersion !== '0.0.0-development' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
562
+ throw new Error(`Native binding package version mismatch, expected 0.0.0-development but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
563
+ }
564
+ return binding
565
+ } catch (e) {
566
+ loadErrors.push(e)
567
+ }
568
+ } else {
569
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
570
+ }
571
+ } else {
572
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
573
+ }
574
+ }
575
+
576
+ nativeBinding = requireNative()
577
+
578
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
579
+ let wasiBinding = null
580
+ let wasiBindingError = null
581
+ try {
582
+ wasiBinding = require('./index.wasi.cjs')
583
+ nativeBinding = wasiBinding
584
+ } catch (err) {
585
+ if (process.env.NAPI_RS_FORCE_WASI) {
586
+ wasiBindingError = err
587
+ }
588
+ }
589
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
590
+ try {
591
+ wasiBinding = (() => { throw new Error('prebuild for this platform is not bundled (and @electron-internal/extract-zip-wasm32-wasi is intentionally not published)') })()
592
+ nativeBinding = wasiBinding
593
+ } catch (err) {
594
+ if (process.env.NAPI_RS_FORCE_WASI) {
595
+ if (!wasiBindingError) {
596
+ wasiBindingError = err
597
+ } else {
598
+ wasiBindingError.cause = err
599
+ }
600
+ loadErrors.push(err)
601
+ }
602
+ }
603
+ }
604
+ if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
605
+ const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
606
+ error.cause = wasiBindingError
607
+ throw error
608
+ }
609
+ }
610
+
611
+ if (!nativeBinding) {
612
+ if (loadErrors.length > 0) {
613
+ throw new Error(
614
+ `Cannot find native binding. ` +
615
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
616
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
617
+ {
618
+ cause: loadErrors.reduce((err, cur) => {
619
+ cur.cause = err
620
+ return cur
621
+ }),
622
+ },
623
+ )
624
+ }
625
+ throw new Error(`Failed to load native binding`)
626
+ }
627
+
628
+ const { extract } = nativeBinding
629
+ export { extract }
package/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export interface ExtractOptions {
2
+ /** Destination directory. Must be an absolute path. */
3
+ dir: string;
4
+ }
5
+
6
+ export declare function extract(zipPath: string, opts: ExtractOptions): Promise<void>;
7
+
8
+ export default extract;
Binary file
package/index.js ADDED
@@ -0,0 +1,23 @@
1
+ import path from 'node:path';
2
+ import { extract as nativeExtract } from './binding.js';
3
+
4
+ /**
5
+ * Extract a zip archive to a directory.
6
+ *
7
+ * await extract(source, { dir: '/abs/path' })
8
+ *
9
+ * @param {string} zipPath
10
+ * @param {import('./index.js').ExtractOptions} opts
11
+ * @returns {Promise<void>}
12
+ */
13
+ export async function extract(zipPath, opts) {
14
+ if (!opts || typeof opts.dir !== 'string') {
15
+ throw new TypeError('extract: opts.dir is required');
16
+ }
17
+ if (!path.isAbsolute(opts.dir)) {
18
+ throw new TypeError('extract: opts.dir must be an absolute path');
19
+ }
20
+ return nativeExtract(zipPath, opts);
21
+ }
22
+
23
+ export default extract;
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@ohos-ports/electron-internal-extract-zip",
3
+ "version": "1.0.5-beta.0",
4
+ "description": "Fast, safe, native zip extraction for Node.js. Drop-in replacement for extract-zip.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./index.d.ts",
9
+ "default": "./index.js"
10
+ }
11
+ },
12
+ "files": [
13
+ "index.js",
14
+ "index.d.ts",
15
+ "binding.js",
16
+ "binding.d.ts",
17
+ "index.*.node"
18
+ ],
19
+ "napi": {
20
+ "binaryName": "index",
21
+ "packageName": "@electron-internal/extract-zip",
22
+ "targets": [
23
+ "x86_64-apple-darwin",
24
+ "aarch64-apple-darwin",
25
+ "universal-apple-darwin",
26
+ "x86_64-pc-windows-msvc",
27
+ "aarch64-pc-windows-msvc",
28
+ "x86_64-unknown-linux-gnu",
29
+ "aarch64-unknown-linux-gnu",
30
+ "x86_64-unknown-linux-musl",
31
+ "aarch64-unknown-linux-musl",
32
+ "i686-unknown-linux-gnu",
33
+ "armv7-unknown-linux-gnueabihf"
34
+ ]
35
+ },
36
+ "scripts": {
37
+ "build": "napi build --platform --release --esm --output-dir . --js binding.js --dts binding.d.ts && node scripts/strip-binding-fallbacks.js",
38
+ "build:debug": "napi build --platform --esm --output-dir . --js binding.js --dts binding.d.ts && node scripts/strip-binding-fallbacks.js",
39
+ "universal": "napi universalize --output-dir .",
40
+ "test": "node --test test/*.test.js",
41
+ "bench": "node bench/bench.js",
42
+ "bench:electron": "node bench/electron.js",
43
+ "prepublishOnly": "node scripts/check-prebuilds.js"
44
+ },
45
+ "keywords": [
46
+ "zip",
47
+ "unzip",
48
+ "extract",
49
+ "native",
50
+ "fast"
51
+ ],
52
+ "license": "BSD-2-Clause",
53
+ "engines": {
54
+ "node": ">=22.12.0"
55
+ },
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "https://github.com/ohos-ports/ohos-ports.git",
59
+ "directory": "ports/@electron-internal/extract-zip/1.0.5"
60
+ },
61
+ "devDependencies": {
62
+ "@napi-rs/cli": "patch:@napi-rs/cli@npm%3A3.6.2#~/.yarn/patches/@napi-rs-cli-npm-3.6.2-b710c59d43.patch",
63
+ "extract-zip": "2.0.1",
64
+ "yazl": "3.3.1"
65
+ },
66
+ "bugs": {
67
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
68
+ }
69
+ }