rar-stream 5.2.1 → 5.3.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 CHANGED
@@ -1,15 +1,19 @@
1
- # rar-stream
1
+ <div align="center">
2
+ <h1>rar-stream</h1>
3
+ </div>
4
+
5
+ <div align="center"><p>
6
+ <a href="https://crates.io/crates/rar-stream"><img alt="Crates.io" src="https://img.shields.io/crates/v/rar-stream?style=for-the-badge&logo=rust&color=C9CBFF&logoColor=D9E0EE&labelColor=302D41" /></a>
7
+ <a href="https://crates.io/crates/rar-stream"><img alt="Crates.io Downloads" src="https://img.shields.io/crates/d/rar-stream?style=for-the-badge&logo=rust&color=A6E3A1&logoColor=D9E0EE&labelColor=302D41" /></a>
8
+ <a href="https://docs.rs/rar-stream"><img alt="docs.rs" src="https://img.shields.io/docsrs/rar-stream?style=for-the-badge&logo=docs.rs&color=8bd5ca&logoColor=D9E0EE&labelColor=302D41" /></a>
9
+ <a href="https://www.npmjs.com/package/rar-stream"><img alt="npm" src="https://img.shields.io/npm/v/rar-stream?style=for-the-badge&logo=npm&color=F5A97F&logoColor=D9E0EE&labelColor=302D41" /></a>
10
+ <a href="https://www.npmjs.com/package/rar-stream"><img alt="npm Downloads" src="https://img.shields.io/npm/dm/rar-stream?style=for-the-badge&logo=npm&color=F5E0DC&logoColor=D9E0EE&labelColor=302D41" /></a>
11
+ <a href="https://github.com/doom-fish/rar-stream#license"><img alt="License" src="https://img.shields.io/crates/l/rar-stream?style=for-the-badge&logo=apache&color=ee999f&logoColor=D9E0EE&labelColor=302D41" /></a>
12
+ <a href="https://github.com/doom-fish/rar-stream/actions"><img alt="Build Status" src="https://img.shields.io/github/actions/workflow/status/doom-fish/rar-stream/ci.yml?branch=main&style=for-the-badge&logo=github&color=c69ff5&logoColor=D9E0EE&labelColor=302D41" /></a>
13
+ </p></div>
2
14
 
3
15
  > Fast RAR archive streaming for Rust, Node.js, and browsers. Zero dependencies core.
4
16
 
5
- [![CI](https://github.com/doom-fish/rar-stream/actions/workflows/ci.yml/badge.svg)](https://github.com/doom-fish/rar-stream/actions/workflows/ci.yml)
6
- [![npm version](https://img.shields.io/npm/v/rar-stream.svg)](https://www.npmjs.com/package/rar-stream)
7
- [![npm downloads](https://img.shields.io/npm/dm/rar-stream.svg)](https://www.npmjs.com/package/rar-stream)
8
- [![crates.io](https://img.shields.io/crates/v/rar-stream.svg)](https://crates.io/crates/rar-stream)
9
- [![crates.io downloads](https://img.shields.io/crates/d/rar-stream.svg)](https://crates.io/crates/rar-stream)
10
- [![docs.rs](https://docs.rs/rar-stream/badge.svg)](https://docs.rs/rar-stream)
11
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
12
-
13
17
  ## Installation
14
18
 
15
19
  ### Node.js
@@ -18,6 +22,8 @@
18
22
  npm install rar-stream
19
23
  ```
20
24
 
25
+ Native binaries are automatically downloaded from [GitHub Releases](https://github.com/doom-fish/rar-stream/releases) during install. Supported platforms: Linux (x64, arm64), macOS (x64, arm64), Windows (x64).
26
+
21
27
  ### Rust
22
28
 
23
29
  ```toml
package/index.d.ts CHANGED
@@ -28,7 +28,7 @@ export interface RarFileInfo {
28
28
  * The buffer should contain at least the first ~300 bytes of a .rar file.
29
29
  */
30
30
  export declare function parseRarHeader(buffer: Buffer): RarFileInfo | null
31
- /** Check if a buffer starts with a RAR signature. */
31
+ /** Check if a buffer starts with a RAR signature (RAR4 or RAR5). */
32
32
  export declare function isRarArchive(buffer: Buffer): boolean
33
33
  /** LocalFileMedia - reads from local filesystem. */
34
34
  export declare class LocalFileMedia {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rar-stream",
3
- "version": "5.2.1",
3
+ "version": "5.3.0",
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,7 +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
- "prepublishOnly": "napi prepublish -t npm --skip-gh-release"
78
+ "postinstall": "node scripts/postinstall.js"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@eslint/js": "^9.0.0",
@@ -100,15 +100,7 @@
100
100
  "pkg/rar_stream.js",
101
101
  "pkg/rar_stream.d.ts",
102
102
  "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
- }
103
+ "pkg/rar_stream_bg.wasm.d.ts",
104
+ "scripts/postinstall.js"
105
+ ]
114
106
  }
@@ -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()