@file-viewer/renderer-archive 3.2.2 → 3.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.en.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @file-viewer/renderer-archive
2
2
 
3
+ [English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/archive/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/archive/README.zh-CN.md)
4
+
3
5
  Standalone archive renderer package for Flyfish File Viewer. It reads ZIP, TAR, GZIP, RAR, 7z, and other archive directories with `libarchive.js` Worker + WASM, then extracts internal files only when the user opens them.
4
6
 
5
7
  ## Usage
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # @file-viewer/renderer-archive
2
2
 
3
- Flyfish File Viewer 的独立压缩包 renderer 包。它用 `libarchive.js` Worker + WASM 读取 RAR、7z、ZIP、TAR 等压缩包目录,并在点击内部文件时才按需解压、缓存和调用 File Viewer 的嵌套渲染能力。
3
+ [English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/archive/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/archive/README.zh-CN.md)
4
4
 
5
- ## 用法
5
+ Standalone archive renderer package for Flyfish File Viewer. It reads ZIP, TAR, GZIP, RAR, 7z, and other archive directories with `libarchive.js` Worker + WASM, then extracts internal files only when the user opens them.
6
+
7
+ ## Usage
6
8
 
7
9
  ```ts
8
10
  import FileViewer from '@file-viewer/vue3'
@@ -14,7 +16,7 @@ const options = {
14
16
  }
15
17
  ```
16
18
 
17
- 也可以和其他 renderer 一起组合:
19
+ You can also compose it with other renderer packages:
18
20
 
19
21
  ```ts
20
22
  import { archiveRenderer } from '@file-viewer/renderer-archive'
@@ -27,27 +29,27 @@ const options = {
27
29
  }
28
30
  ```
29
31
 
30
- ## 能力边界
32
+ ## Capabilities
31
33
 
32
- - 支持 ZIP、TAR、GZIP、RAR、7z 等常见压缩包目录预览。
33
- - `.cbz` / `.cbr` 自动进入漫画阅读模式:只展示图片页,按路径自然排序并自动打开封面,支持翻页按钮、页码、方向键、PageUp/PageDown、Home/End、空格键和触摸滑动。页面继续复用统一图片 renderer 的适屏、缩放和灯箱能力。
34
- - 漫画模式完全复用现有 Worker、RAR4/RAR5、ZIP fallback、密码、按需解压、IndexedDB 缓存、体积限制和资源配置,不维护第二套解包逻辑。
35
- - 自动兼容未声明 UTF-8、实际使用 GBK/GB18030 编码的旧 ZIP 中文文件名。
36
- - 支持加密压缩包:检测到加密内容后使用 `libarchive.js` 统一解密,默认弹框要求用户输入密码,密码正确后继续读取目录或预览内部文件。
37
- - 优先使用 `libarchive.js` Worker + WASM,避免大压缩包阻塞主线程。
38
- - Worker 不可用时自动回退到 ZIP / TAR / GZIP 兼容模式,适合手机 WebView、本地临时服务器和内网静态部署排障;加密压缩包不会走 fallback,必须发布 libarchive Worker/WASM。
39
- - 点击内部文件后才按需解压,并通过 `renderNestedBuffer` 或 core dispatcher 复用 PDF、Office、CAD、XMind、图片、代码等现有 renderer。
40
- - 内置体积上限、单文件预览上限、Worker 超时、IndexedDB 缓存和可配置的内部条目下载入口,避免一次性把压缩包全部展开到内存。
34
+ - Previews ZIP, TAR, GZIP, RAR, 7z, and common archive directories.
35
+ - `.cbz` and `.cbr` automatically enter comic-reading mode: image-only pages, natural path ordering, automatic cover opening, page controls, keyboard shortcuts, and touch swipes. Pages retain the shared image renderer's fit, zoom, and lightbox behavior.
36
+ - Comic mode fully reuses the existing Worker, RAR4/RAR5 support, ZIP fallback, passwords, lazy extraction, IndexedDB cache, size limits, and asset configuration instead of maintaining a second extraction stack.
37
+ - Decodes legacy ZIP entry names that omit the UTF-8 flag but are actually encoded as GBK/GB18030.
38
+ - Supports encrypted archives: encrypted content is handled through the unified `libarchive.js` path, the built-in dialog asks for a password, and a correct password unlocks directory reading or nested entry previews.
39
+ - Uses `libarchive.js` Worker + WASM first to keep large archive parsing off the main thread.
40
+ - Falls back to ZIP / TAR / GZIP parsing when the Worker cannot be started, which helps mobile WebViews, local static servers, and private intranet deployments. Encrypted archives never use the fallback path and require the libarchive Worker/WASM assets.
41
+ - Extracts internal files on demand, then delegates nested previews through `renderNestedBuffer` or the core dispatcher.
42
+ - Includes archive size limits, entry preview limits, worker timeout, IndexedDB cache, and configurable nested-entry download.
41
43
 
42
- ## 离线资产
44
+ ## Offline Assets
43
45
 
44
- 默认会从 viewer assets 下读取:
46
+ Default asset paths are:
45
47
 
46
48
  - `vendor/libarchive/worker-bundle.js`
47
49
  - `vendor/libarchive/libarchive.wasm`
48
50
 
49
- 私有化部署时可以通过 `options.archive.workerUrl` 和 `options.archive.wasmUrl` 覆盖。
50
- Vue 3 / Vue 2.7 / Vue 2.6 full 包默认把 viewer assets 根设为 `/file-viewer/`,会自动指向这两个 libarchive 文件;如果部署在其它静态前缀,先调用对应 full 包导出的 `setDefaultFullAssetBaseUrl('/your-prefix/')` 即可。
51
+ For private deployments, override them with `options.archive.workerUrl` and `options.archive.wasmUrl`.
52
+ The Vue 3 / Vue 2.7 / Vue 2.6 full packages default their viewer asset root to `/file-viewer/` and automatically point to these libarchive files. When deploying under another static prefix, call the matching full package export `setDefaultFullAssetBaseUrl('/your-prefix/')` first.
51
53
 
52
54
  ```ts
53
55
  const options = {
@@ -60,9 +62,9 @@ const options = {
60
62
  }
61
63
  ```
62
64
 
63
- ## 内部条目下载权限
65
+ ## Nested Entry Download Policy
64
66
 
65
- 压缩包内部文件预览栏的下载按钮默认保持可见。需要隐藏时可以配置全局布尔值:
67
+ The download button in the archive entry preview toolbar stays visible by default. Hide it globally with a boolean:
66
68
 
67
69
  ```ts
68
70
  const options = {
@@ -74,7 +76,7 @@ const options = {
74
76
  }
75
77
  ```
76
78
 
77
- 也可以按内部路径、扩展名、大小等元数据做判断:
79
+ Or decide per entry from path, extension, size, and other metadata:
78
80
 
79
81
  ```ts
80
82
  const options = {
@@ -88,11 +90,11 @@ const options = {
88
90
  }
89
91
  ```
90
92
 
91
- 这个选项只影响压缩包内部条目的下载按钮,不会关闭顶层 viewer 下载原始压缩包的工具栏动作。
93
+ This option only controls nested archive entries. The viewer-level toolbar action that downloads the original archive remains controlled by `toolbar` and operation guards.
92
94
 
93
- ## 加密压缩包
95
+ ## Encrypted Archives
94
96
 
95
- 默认情况下,检测到加密内容会显示内置密码弹框。业务也可以预置密码,或接管密码获取流程:
97
+ By default, encrypted archives open a built-in password dialog. Applications can also provide an initial password or take over password collection:
96
98
 
97
99
  ```ts
98
100
  const options = {
@@ -106,8 +108,8 @@ const options = {
106
108
  }
107
109
  ```
108
110
 
109
- `requestPassword` 返回字符串时继续解密;返回 `null` 或 `undefined` 时取消预览并展示友好提示。错误密码会重新请求密码,不会切换到 JSZip fallback。
111
+ Return a string from `requestPassword` to continue. Return `null` or `undefined` to cancel and show a friendly notice. Wrong passwords request another password and never switch to the JSZip fallback.
110
112
 
111
- ## 迁移说明
113
+ ## Migration Note
112
114
 
113
- `@file-viewer/core` 已不再内置 archive renderer,也不再为压缩包链路直接安装 `libarchive.js`。ZIP/TAR/GZIP fallback、`jszip`、缓存和 Worker 逻辑由本包维护;core 在 OFD 完全拆出前可能仍会因 OFD vendor 临时保留 `jszip`。需要压缩包预览时,请显式安装本包,或直接使用 `@file-viewer/preset-all` 聚合能力。
115
+ The core package no longer bundles the archive renderer and no longer installs `libarchive.js` for the archive pipeline. ZIP/TAR/GZIP fallback, `jszip`, cache, and Worker logic are owned by this package; core may still temporarily retain `jszip` for the OFD vendor path until OFD is fully extracted. Install this renderer explicitly, or use `@file-viewer/preset-all`, when archive preview is required.
@@ -0,0 +1,115 @@
1
+ # @file-viewer/renderer-archive
2
+
3
+ [English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/archive/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/archive/README.zh-CN.md)
4
+
5
+ Flyfish File Viewer 的独立压缩包 renderer 包。它用 `libarchive.js` Worker + WASM 读取 RAR、7z、ZIP、TAR 等压缩包目录,并在点击内部文件时才按需解压、缓存和调用 File Viewer 的嵌套渲染能力。
6
+
7
+ ## 用法
8
+
9
+ ```ts
10
+ import FileViewer from '@file-viewer/vue3'
11
+ import { archiveRenderer } from '@file-viewer/renderer-archive'
12
+
13
+ const options = {
14
+ rendererMode: 'replace',
15
+ renderers: archiveRenderer,
16
+ }
17
+ ```
18
+
19
+ 也可以和其他 renderer 一起组合:
20
+
21
+ ```ts
22
+ import { archiveRenderer } from '@file-viewer/renderer-archive'
23
+ import { pdfRenderer } from '@file-viewer/renderer-pdf'
24
+ import { cadRenderer } from '@file-viewer/renderer-cad'
25
+
26
+ const options = {
27
+ rendererMode: 'replace',
28
+ renderers: [pdfRenderer, cadRenderer, archiveRenderer],
29
+ }
30
+ ```
31
+
32
+ ## 能力边界
33
+
34
+ - 支持 ZIP、TAR、GZIP、RAR、7z 等常见压缩包目录预览。
35
+ - `.cbz` / `.cbr` 自动进入漫画阅读模式:只展示图片页,按路径自然排序并自动打开封面,支持翻页按钮、页码、方向键、PageUp/PageDown、Home/End、空格键和触摸滑动。页面继续复用统一图片 renderer 的适屏、缩放和灯箱能力。
36
+ - 漫画模式完全复用现有 Worker、RAR4/RAR5、ZIP fallback、密码、按需解压、IndexedDB 缓存、体积限制和资源配置,不维护第二套解包逻辑。
37
+ - 自动兼容未声明 UTF-8、实际使用 GBK/GB18030 编码的旧 ZIP 中文文件名。
38
+ - 支持加密压缩包:检测到加密内容后使用 `libarchive.js` 统一解密,默认弹框要求用户输入密码,密码正确后继续读取目录或预览内部文件。
39
+ - 优先使用 `libarchive.js` Worker + WASM,避免大压缩包阻塞主线程。
40
+ - Worker 不可用时自动回退到 ZIP / TAR / GZIP 兼容模式,适合手机 WebView、本地临时服务器和内网静态部署排障;加密压缩包不会走 fallback,必须发布 libarchive Worker/WASM。
41
+ - 点击内部文件后才按需解压,并通过 `renderNestedBuffer` 或 core dispatcher 复用 PDF、Office、CAD、XMind、图片、代码等现有 renderer。
42
+ - 内置体积上限、单文件预览上限、Worker 超时、IndexedDB 缓存和可配置的内部条目下载入口,避免一次性把压缩包全部展开到内存。
43
+
44
+ ## 离线资产
45
+
46
+ 默认会从 viewer assets 下读取:
47
+
48
+ - `vendor/libarchive/worker-bundle.js`
49
+ - `vendor/libarchive/libarchive.wasm`
50
+
51
+ 私有化部署时可以通过 `options.archive.workerUrl` 和 `options.archive.wasmUrl` 覆盖。
52
+ Vue 3 / Vue 2.7 / Vue 2.6 full 包默认把 viewer assets 根设为 `/file-viewer/`,会自动指向这两个 libarchive 文件;如果部署在其它静态前缀,先调用对应 full 包导出的 `setDefaultFullAssetBaseUrl('/your-prefix/')` 即可。
53
+
54
+ ```ts
55
+ const options = {
56
+ archive: {
57
+ workerUrl: '/file-viewer/vendor/libarchive/worker-bundle.js',
58
+ wasmUrl: '/file-viewer/vendor/libarchive/libarchive.wasm',
59
+ cache: true,
60
+ workerTimeoutMs: 30000,
61
+ },
62
+ }
63
+ ```
64
+
65
+ ## 内部条目下载权限
66
+
67
+ 压缩包内部文件预览栏的下载按钮默认保持可见。需要隐藏时可以配置全局布尔值:
68
+
69
+ ```ts
70
+ const options = {
71
+ archive: {
72
+ entryActions: {
73
+ download: false,
74
+ },
75
+ },
76
+ }
77
+ ```
78
+
79
+ 也可以按内部路径、扩展名、大小等元数据做判断:
80
+
81
+ ```ts
82
+ const options = {
83
+ archive: {
84
+ entryActions: {
85
+ download(entry) {
86
+ return entry.path.startsWith('public/')
87
+ },
88
+ },
89
+ },
90
+ }
91
+ ```
92
+
93
+ 这个选项只影响压缩包内部条目的下载按钮,不会关闭顶层 viewer 下载原始压缩包的工具栏动作。
94
+
95
+ ## 加密压缩包
96
+
97
+ 默认情况下,检测到加密内容会显示内置密码弹框。业务也可以预置密码,或接管密码获取流程:
98
+
99
+ ```ts
100
+ const options = {
101
+ archive: {
102
+ password: initialPasswordFromYourSystem,
103
+ async requestPassword(context) {
104
+ // context.filename / context.entryName / context.reason / context.attempt
105
+ return await openYourPermissionCheckedPasswordModal(context)
106
+ },
107
+ },
108
+ }
109
+ ```
110
+
111
+ `requestPassword` 返回字符串时继续解密;返回 `null` 或 `undefined` 时取消预览并展示友好提示。错误密码会重新请求密码,不会切换到 JSZip fallback。
112
+
113
+ ## 迁移说明
114
+
115
+ `@file-viewer/core` 已不再内置 archive renderer,也不再为压缩包链路直接安装 `libarchive.js`。ZIP/TAR/GZIP fallback、`jszip`、缓存和 Worker 逻辑由本包维护;core 在 OFD 完全拆出前可能仍会因 OFD vendor 临时保留 `jszip`。需要压缩包预览时,请显式安装本包,或直接使用 `@file-viewer/preset-all` 聚合能力。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-archive",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Standalone archive renderer plugin for File Viewer with libarchive worker, ZIP/TAR fallback, IndexedDB cache, and nested previews.",
@@ -68,10 +68,11 @@
68
68
  "file-viewer.capability.json",
69
69
  "LICENSE",
70
70
  "README.en.md",
71
- "README.md"
71
+ "README.md",
72
+ "README.zh-CN.md"
72
73
  ],
73
74
  "dependencies": {
74
- "@file-viewer/core": "3.2.2",
75
+ "@file-viewer/core": "3.3.0",
75
76
  "jszip": "3.10.2",
76
77
  "libarchive.js": "^2.0.2"
77
78
  },