rar-stream 5.2.1 → 5.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rar-stream",
3
- "version": "5.2.1",
3
+ "version": "5.2.2",
4
4
  "description": "RAR streaming library - Rust implementation with NAPI and WASM bindings",
5
5
  "main": "lib/index.mjs",
6
6
  "browser": "lib/browser.mjs",
@@ -75,6 +75,7 @@
75
75
  "bench:compare": "cargo bench -- --baseline main",
76
76
  "profile": "cargo build --release && perf record -g ./target/release/examples/profile_decompress && perf report",
77
77
  "flamegraph": "cargo flamegraph --bench decompress -- --bench",
78
+ "postinstall": "node scripts/postinstall.js",
78
79
  "prepublishOnly": "napi prepublish -t npm --skip-gh-release"
79
80
  },
80
81
  "devDependencies": {
@@ -100,15 +101,7 @@
100
101
  "pkg/rar_stream.js",
101
102
  "pkg/rar_stream.d.ts",
102
103
  "pkg/rar_stream_bg.wasm",
103
- "pkg/rar_stream_bg.wasm.d.ts"
104
- ],
105
- "optionalDependencies": {
106
- "rar-stream-win32-x64-msvc": "5.2.1",
107
- "rar-stream-darwin-x64": "5.2.1",
108
- "rar-stream-linux-x64-gnu": "5.2.1",
109
- "rar-stream-linux-x64-musl": "5.2.1",
110
- "rar-stream-linux-arm64-gnu": "5.2.1",
111
- "rar-stream-darwin-arm64": "5.2.1",
112
- "rar-stream-linux-arm64-musl": "5.2.1"
113
- }
104
+ "pkg/rar_stream_bg.wasm.d.ts",
105
+ "scripts/postinstall.js"
106
+ ]
114
107
  }
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ 'use strict'
3
+
4
+ const { existsSync, readFileSync, createWriteStream, unlinkSync } = require('fs')
5
+ const { join } = require('path')
6
+ const https = require('https')
7
+ const http = require('http')
8
+
9
+ const REPO = 'doom-fish/rar-stream'
10
+ const PKG_DIR = join(__dirname, '..')
11
+
12
+ function isMusl() {
13
+ if (!process.report || typeof process.report.getReport !== 'function') {
14
+ try {
15
+ const lddPath = require('child_process').execSync('which ldd').toString().trim()
16
+ return readFileSync(lddPath, 'utf8').includes('musl')
17
+ } catch {
18
+ return true
19
+ }
20
+ }
21
+ const { glibcVersionRuntime } = process.report.getReport().header
22
+ return !glibcVersionRuntime
23
+ }
24
+
25
+ function getBinaryName() {
26
+ const { platform, arch } = process
27
+ switch (platform) {
28
+ case 'win32':
29
+ if (arch === 'x64') return 'rar-stream.win32-x64-msvc.node'
30
+ break
31
+ case 'darwin':
32
+ if (arch === 'x64') return 'rar-stream.darwin-x64.node'
33
+ if (arch === 'arm64') return 'rar-stream.darwin-arm64.node'
34
+ break
35
+ case 'linux':
36
+ if (arch === 'x64') return isMusl() ? 'rar-stream.linux-x64-musl.node' : 'rar-stream.linux-x64-gnu.node'
37
+ if (arch === 'arm64') return isMusl() ? 'rar-stream.linux-arm64-musl.node' : 'rar-stream.linux-arm64-gnu.node'
38
+ break
39
+ }
40
+ return null
41
+ }
42
+
43
+ function download(url) {
44
+ return new Promise((resolve, reject) => {
45
+ const client = url.startsWith('https') ? https : http
46
+ client.get(url, { headers: { 'User-Agent': 'rar-stream-postinstall' } }, (res) => {
47
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
48
+ return download(res.headers.location).then(resolve, reject)
49
+ }
50
+ if (res.statusCode !== 200) {
51
+ res.resume()
52
+ return reject(new Error(`HTTP ${res.statusCode} for ${url}`))
53
+ }
54
+ resolve(res)
55
+ }).on('error', reject)
56
+ })
57
+ }
58
+
59
+ async function main() {
60
+ const binaryName = getBinaryName()
61
+ if (!binaryName) {
62
+ console.log(`rar-stream: no prebuilt binary for ${process.platform}-${process.arch}, skipping download`)
63
+ return
64
+ }
65
+
66
+ const dest = join(PKG_DIR, binaryName)
67
+ if (existsSync(dest)) return // already present (local build or cached)
68
+
69
+ const version = require(join(PKG_DIR, 'package.json')).version
70
+ const url = `https://github.com/${REPO}/releases/download/v${version}/${binaryName}`
71
+
72
+ console.log(`rar-stream: downloading ${binaryName} from GitHub Release v${version}...`)
73
+
74
+ try {
75
+ const res = await download(url)
76
+ const file = createWriteStream(dest)
77
+ await new Promise((resolve, reject) => {
78
+ res.pipe(file)
79
+ file.on('finish', resolve)
80
+ file.on('error', (err) => { unlinkSync(dest); reject(err) })
81
+ })
82
+ console.log(`rar-stream: installed ${binaryName}`)
83
+ } catch (err) {
84
+ console.warn(`rar-stream: failed to download binary (${err.message}). You may need to build from source.`)
85
+ }
86
+ }
87
+
88
+ main()