@file-viewer/renderer-archive 3.1.2 → 3.2.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,113 +1,7 @@
1
1
  # @file-viewer/renderer-archive
2
2
 
3
- 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.
3
+ Runtime package version 3.2.0.
4
4
 
5
- ## Usage
5
+ Usage and API documentation: https://doc.file-viewer.app/guide/on-demand-renderers
6
6
 
7
- ```ts
8
- import FileViewer from '@file-viewer/vue3'
9
- import { archiveRenderer } from '@file-viewer/renderer-archive'
10
-
11
- const options = {
12
- rendererMode: 'replace',
13
- renderers: archiveRenderer,
14
- }
15
- ```
16
-
17
- You can also compose it with other renderer packages:
18
-
19
- ```ts
20
- import { archiveRenderer } from '@file-viewer/renderer-archive'
21
- import { pdfRenderer } from '@file-viewer/renderer-pdf'
22
- import { cadRenderer } from '@file-viewer/renderer-cad'
23
-
24
- const options = {
25
- rendererMode: 'replace',
26
- renderers: [pdfRenderer, cadRenderer, archiveRenderer],
27
- }
28
- ```
29
-
30
- ## Capabilities
31
-
32
- - Previews ZIP, TAR, GZIP, RAR, 7z, and common archive directories.
33
- - `.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.
34
- - 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.
35
- - Decodes legacy ZIP entry names that omit the UTF-8 flag but are actually encoded as GBK/GB18030.
36
- - 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.
37
- - Uses `libarchive.js` Worker + WASM first to keep large archive parsing off the main thread.
38
- - 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.
39
- - Extracts internal files on demand, then delegates nested previews through `renderNestedBuffer` or the core dispatcher.
40
- - Includes archive size limits, entry preview limits, worker timeout, IndexedDB cache, and configurable nested-entry download.
41
-
42
- ## Offline Assets
43
-
44
- Default asset paths are:
45
-
46
- - `vendor/libarchive/worker-bundle.js`
47
- - `vendor/libarchive/libarchive.wasm`
48
-
49
- For private deployments, override them with `options.archive.workerUrl` and `options.archive.wasmUrl`.
50
- 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
-
52
- ```ts
53
- const options = {
54
- archive: {
55
- workerUrl: '/file-viewer/vendor/libarchive/worker-bundle.js',
56
- wasmUrl: '/file-viewer/vendor/libarchive/libarchive.wasm',
57
- cache: true,
58
- workerTimeoutMs: 30000,
59
- },
60
- }
61
- ```
62
-
63
- ## Nested Entry Download Policy
64
-
65
- The download button in the archive entry preview toolbar stays visible by default. Hide it globally with a boolean:
66
-
67
- ```ts
68
- const options = {
69
- archive: {
70
- entryActions: {
71
- download: false,
72
- },
73
- },
74
- }
75
- ```
76
-
77
- Or decide per entry from path, extension, size, and other metadata:
78
-
79
- ```ts
80
- const options = {
81
- archive: {
82
- entryActions: {
83
- download(entry) {
84
- return entry.path.startsWith('public/')
85
- },
86
- },
87
- },
88
- }
89
- ```
90
-
91
- 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
-
93
- ## Encrypted Archives
94
-
95
- By default, encrypted archives open a built-in password dialog. Applications can also provide an initial password or take over password collection:
96
-
97
- ```ts
98
- const options = {
99
- archive: {
100
- password: initialPasswordFromYourSystem,
101
- async requestPassword(context) {
102
- // context.filename / context.entryName / context.reason / context.attempt
103
- return await openYourPermissionCheckedPasswordModal(context)
104
- },
105
- },
106
- }
107
- ```
108
-
109
- 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
-
111
- ## Migration Note
112
-
113
- 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.
7
+ The package's own license is Apache-2.0. Included third-party notices apply to their respective components.
package/README.md CHANGED
@@ -1,113 +1,7 @@
1
1
  # @file-viewer/renderer-archive
2
2
 
3
- Flyfish File Viewer 的独立压缩包 renderer 包。它用 `libarchive.js` Worker + WASM 读取 RAR、7z、ZIP、TAR 等压缩包目录,并在点击内部文件时才按需解压、缓存和调用 File Viewer 的嵌套渲染能力。
3
+ Runtime package version 3.2.0.
4
4
 
5
- ## 用法
5
+ Usage and API documentation: https://doc.file-viewer.app/guide/on-demand-renderers
6
6
 
7
- ```ts
8
- import FileViewer from '@file-viewer/vue3'
9
- import { archiveRenderer } from '@file-viewer/renderer-archive'
10
-
11
- const options = {
12
- rendererMode: 'replace',
13
- renderers: archiveRenderer,
14
- }
15
- ```
16
-
17
- 也可以和其他 renderer 一起组合:
18
-
19
- ```ts
20
- import { archiveRenderer } from '@file-viewer/renderer-archive'
21
- import { pdfRenderer } from '@file-viewer/renderer-pdf'
22
- import { cadRenderer } from '@file-viewer/renderer-cad'
23
-
24
- const options = {
25
- rendererMode: 'replace',
26
- renderers: [pdfRenderer, cadRenderer, archiveRenderer],
27
- }
28
- ```
29
-
30
- ## 能力边界
31
-
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 缓存和可配置的内部条目下载入口,避免一次性把压缩包全部展开到内存。
41
-
42
- ## 离线资产
43
-
44
- 默认会从 viewer assets 下读取:
45
-
46
- - `vendor/libarchive/worker-bundle.js`
47
- - `vendor/libarchive/libarchive.wasm`
48
-
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
-
52
- ```ts
53
- const options = {
54
- archive: {
55
- workerUrl: '/file-viewer/vendor/libarchive/worker-bundle.js',
56
- wasmUrl: '/file-viewer/vendor/libarchive/libarchive.wasm',
57
- cache: true,
58
- workerTimeoutMs: 30000,
59
- },
60
- }
61
- ```
62
-
63
- ## 内部条目下载权限
64
-
65
- 压缩包内部文件预览栏的下载按钮默认保持可见。需要隐藏时可以配置全局布尔值:
66
-
67
- ```ts
68
- const options = {
69
- archive: {
70
- entryActions: {
71
- download: false,
72
- },
73
- },
74
- }
75
- ```
76
-
77
- 也可以按内部路径、扩展名、大小等元数据做判断:
78
-
79
- ```ts
80
- const options = {
81
- archive: {
82
- entryActions: {
83
- download(entry) {
84
- return entry.path.startsWith('public/')
85
- },
86
- },
87
- },
88
- }
89
- ```
90
-
91
- 这个选项只影响压缩包内部条目的下载按钮,不会关闭顶层 viewer 下载原始压缩包的工具栏动作。
92
-
93
- ## 加密压缩包
94
-
95
- 默认情况下,检测到加密内容会显示内置密码弹框。业务也可以预置密码,或接管密码获取流程:
96
-
97
- ```ts
98
- const options = {
99
- archive: {
100
- password: initialPasswordFromYourSystem,
101
- async requestPassword(context) {
102
- // context.filename / context.entryName / context.reason / context.attempt
103
- return await openYourPermissionCheckedPasswordModal(context)
104
- },
105
- },
106
- }
107
- ```
108
-
109
- `requestPassword` 返回字符串时继续解密;返回 `null` 或 `undefined` 时取消预览并展示友好提示。错误密码会重新请求密码,不会切换到 JSZip fallback。
110
-
111
- ## 迁移说明
112
-
113
- `@file-viewer/core` 已不再内置 archive renderer,也不再为压缩包链路直接安装 `libarchive.js`。ZIP/TAR/GZIP fallback、`jszip`、缓存和 Worker 逻辑由本包维护;core 在 OFD 完全拆出前可能仍会因 OFD vendor 临时保留 `jszip`。需要压缩包预览时,请显式安装本包,或直接使用 `@file-viewer/preset-all` 聚合能力。
7
+ The package's own license is Apache-2.0. Included third-party notices apply to their respective components.
package/dist/archive.js CHANGED
@@ -2,11 +2,10 @@ import { resolveFileViewerArchiveWasmUrl, resolveFileViewerArchiveWorkerUrl, res
2
2
  import { collectFileViewerRendererPlugins, createFileRenderHandlerLoader, createFileViewerCoreRendererRegistry, createFileViewerTranslator, createRendererRegistry, disposeFileViewerRendered, installFileViewerRendererPlugins, listFileViewerAutoRendererPresets, normalizeFileViewerUiDensity, normalizeSource, resolveFileViewerRendererPresetInputs, } from '@file-viewer/core';
3
3
  import { buildArchiveNestedRenderContext, createArchiveCacheKey, flattenArchiveObject, formatArchiveBytes, getArchiveEntryExtension, isArchiveEntryDownloadAllowed, } from './archiveShared.js';
4
4
  import { readArchiveCache, writeArchiveCache } from './archiveCache.js';
5
+ import { resolveArchiveLimits } from './archiveLimits.js';
5
6
  import { hasLikelyGbkZipFilenames, isLikelyEncryptedArchive, loadArchiveEntriesWithoutWorker, } from './archiveFallback.js';
6
7
  import { comicBookStyle, createComicBookController, } from './comicBook.js';
7
8
  import { createShapefileBundleArchive, getShapefileBundleEntries, } from './shapefileBundle.js';
8
- const DEFAULT_MAX_ARCHIVE_SIZE = 320 * 1024 * 1024;
9
- const DEFAULT_MAX_ENTRY_PREVIEW_SIZE = 64 * 1024 * 1024;
10
9
  const DEFAULT_WORKER_TIMEOUT_MS = 30000;
11
10
  const MAX_LISTED_ENTRIES = 5000;
12
11
  class ArchivePasswordCancelledError extends Error {
@@ -225,7 +224,6 @@ const probeWorkerUrl = async (url) => {
225
224
  }
226
225
  }
227
226
  catch {
228
- // Some local servers do not support HEAD; continue with a tiny GET probe.
229
227
  }
230
228
  try {
231
229
  const response = await fetch(url, {
@@ -324,8 +322,7 @@ export default async function renderArchive(buffer, target, _type, context) {
324
322
  const archiveOptions = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.archive;
325
323
  const filename = (context === null || context === void 0 ? void 0 : context.filename) || 'archive.bin';
326
324
  const sourceExtension = (_type || getArchiveEntryExtension(filename)).toLowerCase();
327
- const maxArchiveSize = (archiveOptions === null || archiveOptions === void 0 ? void 0 : archiveOptions.maxArchiveSize) || DEFAULT_MAX_ARCHIVE_SIZE;
328
- const maxEntryPreviewSize = (archiveOptions === null || archiveOptions === void 0 ? void 0 : archiveOptions.maxEntryPreviewSize) || DEFAULT_MAX_ENTRY_PREVIEW_SIZE;
325
+ const { maxArchiveSize, maxEntryPreviewSize } = resolveArchiveLimits(archiveOptions);
329
326
  const cacheEnabled = (archiveOptions === null || archiveOptions === void 0 ? void 0 : archiveOptions.cache) !== false;
330
327
  const workerTimeoutMs = (archiveOptions === null || archiveOptions === void 0 ? void 0 : archiveOptions.workerTimeoutMs) || DEFAULT_WORKER_TIMEOUT_MS;
331
328
  const hasLegacyGbkZipFilenames = hasLikelyGbkZipFilenames(buffer, filename);
@@ -706,7 +703,10 @@ export default async function renderArchive(buffer, target, _type, context) {
706
703
  : t('archive.loading.readingDirectory'), showWorkerFallbackNotice
707
704
  ? t('archive.loading.workerFallbackHint')
708
705
  : t('archive.loading.directoryReadyHint'));
709
- const fallbackEntries = await loadArchiveEntriesWithoutWorker(buffer, filename);
706
+ const fallbackEntries = await loadArchiveEntriesWithoutWorker(buffer, filename, {
707
+ maxArchiveSize,
708
+ maxEntryPreviewSize,
709
+ });
710
710
  if (!fallbackEntries) {
711
711
  return false;
712
712
  }
@@ -76,7 +76,6 @@ const pruneArchiveCache = async () => {
76
76
  });
77
77
  }
78
78
  catch {
79
- // Cache pruning is a best-effort optimization and must not block preview.
80
79
  }
81
80
  };
82
81
  export const writeArchiveCache = async (entry) => {
@@ -91,6 +90,5 @@ export const writeArchiveCache = async (entry) => {
91
90
  await pruneArchiveCache();
92
91
  }
93
92
  catch {
94
- // Quota, private-mode, or browser policy errors simply disable cache writes.
95
93
  }
96
94
  };
@@ -1,4 +1,5 @@
1
1
  import { type ArchiveEntryView } from './archiveShared.js';
2
+ import { type ArchiveLimits } from './archiveLimits.js';
2
3
  type JSZipLike = {
3
4
  loadAsync(data: ArrayBuffer, options?: {
4
5
  decodeFileName?: (bytes: Uint8Array | number[]) => string;
@@ -14,10 +15,5 @@ export declare const decodeZipFilename: (bytes: Uint8Array | number[]) => string
14
15
  export declare const resolveJSZip: (module: unknown) => JSZipLike;
15
16
  export declare const hasLikelyGbkZipFilenames: (data: ArrayBuffer, filename: string) => boolean;
16
17
  export declare const isLikelyEncryptedArchive: (data: ArrayBuffer, filename: string) => boolean;
17
- /**
18
- * Worker fallback for constrained browsers, temporary local servers, and
19
- * mobile WebViews. The main libarchive path still covers broader formats;
20
- * this covers common ZIP/TAR/GZIP archives without an extra static Worker.
21
- */
22
- export declare const loadArchiveEntriesWithoutWorker: (data: ArrayBuffer, filename: string) => Promise<ArchiveEntryView[] | null>;
18
+ export declare const loadArchiveEntriesWithoutWorker: (data: ArrayBuffer, filename: string, limits?: ArchiveLimits) => Promise<ArchiveEntryView[] | null>;
23
19
  export {};
@@ -1,4 +1,5 @@
1
1
  import { getArchiveEntryExtension, isArchiveSystemMetadataPath, isPreviewableArchiveEntry, } from './archiveShared.js';
2
+ import { resolveArchiveLimits } from './archiveLimits.js';
2
3
  const ZIP_LIKE_EXTENSIONS = new Set(['zip', 'zipx', 'jar', 'war', 'ear', 'apk', 'cbz']);
3
4
  const TAR_LIKE_EXTENSIONS = new Set(['tar', 'tgz', 'gz', 'gzip']);
4
5
  const TAR_BLOCK_SIZE = 512;
@@ -8,7 +9,7 @@ const ZIP_GENERAL_PURPOSE_ENCRYPTED_FLAG = 0x0001;
8
9
  const ZIP_GENERAL_PURPOSE_UTF8_FLAG = 0x0800;
9
10
  const UTF8_DECODER = new TextDecoder('utf-8');
10
11
  const UTF8_FATAL_DECODER = new TextDecoder('utf-8', { fatal: true });
11
- const CJK_TEXT_PATTERN = /[\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]/;
12
+ const GBK_FILENAME_TEXT_PATTERN = /[\u2460-\u24ff\u3000-\u303f\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff01-\uff60]/;
12
13
  const isJSZipLike = (value) => {
13
14
  return !!value &&
14
15
  (typeof value === 'object' || typeof value === 'function') &&
@@ -16,7 +17,7 @@ const isJSZipLike = (value) => {
16
17
  };
17
18
  const createTextDecoder = (label) => {
18
19
  try {
19
- return new TextDecoder(label);
20
+ return new TextDecoder(label, { fatal: true });
20
21
  }
21
22
  catch {
22
23
  return null;
@@ -46,12 +47,11 @@ export const decodeZipFilename = (bytes) => {
46
47
  return utf8;
47
48
  }
48
49
  const gbk = decodeGbk(data);
49
- if (gbk && CJK_TEXT_PATTERN.test(gbk)) {
50
+ if (gbk && GBK_FILENAME_TEXT_PATTERN.test(gbk)) {
50
51
  return gbk;
51
52
  }
52
53
  return UTF8_DECODER.decode(data);
53
54
  };
54
- // Vite can expose the CJS constructor as a function-shaped default export.
55
55
  export const resolveJSZip = (module) => {
56
56
  const record = module;
57
57
  const defaultRecord = record === null || record === void 0 ? void 0 : record.default;
@@ -72,14 +72,48 @@ const toArrayBuffer = (bytes) => {
72
72
  output.set(bytes);
73
73
  return output.buffer;
74
74
  };
75
- const decompressBytes = async (bytes, format) => {
75
+ const expandedSizeError = (limit) => {
76
+ return new RangeError(`Archive expanded data exceeds the configured limit of ${limit} bytes.`);
77
+ };
78
+ const decompressBytes = async (bytes, format, maxBytes) => {
76
79
  if (typeof DecompressionStream === 'undefined') {
77
80
  return null;
78
81
  }
79
82
  const stream = new Blob([toArrayBuffer(bytes)])
80
83
  .stream()
81
84
  .pipeThrough(new DecompressionStream(format));
82
- return new Uint8Array(await new Response(stream).arrayBuffer());
85
+ const reader = stream.getReader();
86
+ const chunks = [];
87
+ let size = 0;
88
+ try {
89
+ for (;;) {
90
+ const { done, value } = await reader.read();
91
+ if (done) {
92
+ break;
93
+ }
94
+ if (value.byteLength > maxBytes - size) {
95
+ throw expandedSizeError(maxBytes);
96
+ }
97
+ size += value.byteLength;
98
+ if (value.byteLength) {
99
+ chunks.push(value);
100
+ }
101
+ }
102
+ const output = new Uint8Array(size);
103
+ let offset = 0;
104
+ for (const chunk of chunks) {
105
+ output.set(chunk, offset);
106
+ offset += chunk.byteLength;
107
+ }
108
+ return output;
109
+ }
110
+ catch (error) {
111
+ await reader.cancel(error).catch(() => undefined);
112
+ throw error;
113
+ }
114
+ finally {
115
+ reader.releaseLock();
116
+ }
83
117
  };
84
118
  const normalizeArchivePath = (path) => {
85
119
  return path.replace(/^\/+/, '').replace(/\\/g, '/');
@@ -143,7 +177,7 @@ const parseTarEntries = (bytes) => {
143
177
  const typeFlag = String.fromCharCode(bytes[offset + 156] || 0);
144
178
  const dataOffset = offset + TAR_BLOCK_SIZE;
145
179
  const nextOffset = dataOffset + Math.ceil(size / TAR_BLOCK_SIZE) * TAR_BLOCK_SIZE;
146
- if (path && typeFlag !== '5' && !isArchiveSystemMetadataPath(path)) {
180
+ if (path && typeFlag !== '5' && typeFlag !== 'x' && typeFlag !== 'g' && !isArchiveSystemMetadataPath(path)) {
147
181
  const fileBytes = bytes.slice(dataOffset, dataOffset + size);
148
182
  entries.push(createEntryView({
149
183
  path,
@@ -205,8 +239,8 @@ export const hasLikelyGbkZipFilenames = (data, filename) => {
205
239
  }
206
240
  if ((flag & ZIP_GENERAL_PURPOSE_UTF8_FLAG) === 0) {
207
241
  const rawName = new Uint8Array(data, nameStart, nameLength);
208
- const decoded = decodeZipFilename(rawName);
209
- if (CJK_TEXT_PATTERN.test(decoded)) {
242
+ const decoded = decodeUtf8Strict(rawName) === null ? decodeGbk(rawName) : null;
243
+ if (decoded && GBK_FILENAME_TEXT_PATTERN.test(decoded)) {
210
244
  return true;
211
245
  }
212
246
  }
@@ -256,34 +290,33 @@ const loadZipEntries = async (data) => {
256
290
  });
257
291
  return entries;
258
292
  };
259
- const loadTarEntries = async (data, filename, extension) => {
293
+ const loadTarEntries = async (data, filename, extension, options) => {
294
+ const { maxArchiveSize, maxEntryPreviewSize } = resolveArchiveLimits(options);
295
+ const isSingleGzipEntry = extension === 'gz' || extension === 'gzip';
296
+ const maxExpandedSize = isSingleGzipEntry
297
+ ? Math.min(maxArchiveSize, maxEntryPreviewSize)
298
+ : maxArchiveSize;
260
299
  const source = new Uint8Array(data);
300
+ if (extension === 'tar' && source.byteLength > maxExpandedSize) {
301
+ throw expandedSizeError(maxExpandedSize);
302
+ }
261
303
  const bytes = extension === 'tar'
262
304
  ? source
263
- : await decompressBytes(source, 'gzip');
305
+ : await decompressBytes(source, 'gzip', maxExpandedSize);
264
306
  if (!bytes) {
265
307
  return null;
266
308
  }
267
- if (extension === 'gz' || extension === 'gzip') {
268
- const lower = filename.toLowerCase();
269
- const isTarGz = lower.endsWith('.tar.gz') || lower.endsWith('.tgz');
270
- if (!isTarGz) {
271
- const name = getGzipEntryName(filename);
272
- return [createEntryView({
273
- path: name,
274
- size: bytes.byteLength,
275
- load: async () => toArrayBuffer(bytes),
276
- })];
277
- }
309
+ if (isSingleGzipEntry) {
310
+ const name = getGzipEntryName(filename);
311
+ return [createEntryView({
312
+ path: name,
313
+ size: bytes.byteLength,
314
+ load: async () => toArrayBuffer(bytes),
315
+ })];
278
316
  }
279
317
  return parseTarEntries(bytes);
280
318
  };
281
- /**
282
- * Worker fallback for constrained browsers, temporary local servers, and
283
- * mobile WebViews. The main libarchive path still covers broader formats;
284
- * this covers common ZIP/TAR/GZIP archives without an extra static Worker.
285
- */
286
- export const loadArchiveEntriesWithoutWorker = async (data, filename) => {
319
+ export const loadArchiveEntriesWithoutWorker = async (data, filename, limits) => {
287
320
  const extension = getArchiveExtension(filename);
288
321
  if (ZIP_LIKE_EXTENSIONS.has(extension)) {
289
322
  if (isLikelyEncryptedArchive(data, filename)) {
@@ -292,7 +325,7 @@ export const loadArchiveEntriesWithoutWorker = async (data, filename) => {
292
325
  return loadZipEntries(data);
293
326
  }
294
327
  if (TAR_LIKE_EXTENSIONS.has(extension)) {
295
- return loadTarEntries(data, filename, extension);
328
+ return loadTarEntries(data, filename, extension, limits);
296
329
  }
297
330
  return null;
298
331
  };
@@ -0,0 +1,6 @@
1
+ import type { FileViewerArchiveOptions } from '@file-viewer/core';
2
+ export type ArchiveLimits = Pick<FileViewerArchiveOptions, 'maxArchiveSize' | 'maxEntryPreviewSize'>;
3
+ export declare const resolveArchiveLimits: (options?: ArchiveLimits) => {
4
+ maxArchiveSize: number;
5
+ maxEntryPreviewSize: number;
6
+ };
@@ -0,0 +1,13 @@
1
+ const DEFAULT_MAX_ARCHIVE_SIZE = 320 * 1024 * 1024;
2
+ const DEFAULT_MAX_ENTRY_PREVIEW_SIZE = 64 * 1024 * 1024;
3
+ const resolveByteLimit = (value, fallback, name) => {
4
+ const limit = value === undefined ? fallback : value;
5
+ if (!Number.isSafeInteger(limit) || limit < 0) {
6
+ throw new RangeError(`${name} must be a non-negative safe integer byte limit.`);
7
+ }
8
+ return limit;
9
+ };
10
+ export const resolveArchiveLimits = (options) => ({
11
+ maxArchiveSize: resolveByteLimit(options === null || options === void 0 ? void 0 : options.maxArchiveSize, DEFAULT_MAX_ARCHIVE_SIZE, 'maxArchiveSize'),
12
+ maxEntryPreviewSize: resolveByteLimit(options === null || options === void 0 ? void 0 : options.maxEntryPreviewSize, DEFAULT_MAX_ENTRY_PREVIEW_SIZE, 'maxEntryPreviewSize'),
13
+ });
@@ -117,9 +117,6 @@ const buildNestedOptions = (context, archiveOptions) => ({
117
117
  export const buildArchiveNestedRenderContext = (context, entry, archiveOptions) => ({
118
118
  ...context,
119
119
  filename: entry.name,
120
- // Archive children are rendered from the extracted bytes. Never inherit
121
- // the parent archive URL, otherwise streaming renderers such as PDF.js
122
- // would try to parse the .zip/.rar source as the nested file.
123
120
  url: undefined,
124
121
  streamUrl: undefined,
125
122
  options: buildNestedOptions(context, archiveOptions),
@@ -1,16 +1,3 @@
1
1
  import { type ArchiveEntryView } from './archiveShared.js';
2
- /**
3
- * Finds the files that form the selected Shapefile dataset. Shapefile
4
- * sidecars are matched case-insensitively by directory and basename so an
5
- * archive containing multiple datasets never leaks attributes or projection
6
- * metadata from a neighbouring dataset into the preview.
7
- */
8
2
  export declare const getShapefileBundleEntries: (entries: readonly ArchiveEntryView[], selectedEntry: ArchiveEntryView) => ArchiveEntryView[];
9
- /**
10
- * shpjs accepts an ArrayBuffer ZIP for a complete Shapefile dataset. Archive
11
- * previews normally extract one entry at a time, so rebuild a small STORE-only
12
- * ZIP from the selected .shp and its sidecars before delegating to the existing
13
- * geospatial renderer. STORE avoids wasting CPU recompressing already
14
- * compressed archive data.
15
- */
16
3
  export declare const createShapefileBundleArchive: (entries: readonly ArchiveEntryView[], readEntry: (entry: ArchiveEntryView) => Promise<ArrayBuffer>) => Promise<ArrayBuffer>;
@@ -47,12 +47,6 @@ const resolveJSZipWriter = (module) => {
47
47
  }
48
48
  return constructor;
49
49
  };
50
- /**
51
- * Finds the files that form the selected Shapefile dataset. Shapefile
52
- * sidecars are matched case-insensitively by directory and basename so an
53
- * archive containing multiple datasets never leaks attributes or projection
54
- * metadata from a neighbouring dataset into the preview.
55
- */
56
50
  export const getShapefileBundleEntries = (entries, selectedEntry) => {
57
51
  const selected = getArchivePathParts(selectedEntry.path);
58
52
  if (selected.extension !== 'shp') {
@@ -73,13 +67,6 @@ export const getShapefileBundleEntries = (entries, selectedEntry) => {
73
67
  ((_b = SHAPEFILE_COMPONENT_ORDER.get(rightExtension)) !== null && _b !== void 0 ? _b : Number.MAX_SAFE_INTEGER);
74
68
  });
75
69
  };
76
- /**
77
- * shpjs accepts an ArrayBuffer ZIP for a complete Shapefile dataset. Archive
78
- * previews normally extract one entry at a time, so rebuild a small STORE-only
79
- * ZIP from the selected .shp and its sidecars before delegating to the existing
80
- * geospatial renderer. STORE avoids wasting CPU recompressing already
81
- * compressed archive data.
82
- */
83
70
  export const createShapefileBundleArchive = async (entries, readEntry) => {
84
71
  const JSZip = resolveJSZipWriter(await import('jszip'));
85
72
  const zip = new JSZip();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-archive",
3
- "version": "3.1.2",
3
+ "version": "3.2.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.",
@@ -27,8 +27,7 @@
27
27
  },
28
28
  "repository": {
29
29
  "type": "git",
30
- "url": "git+https://github.com/flyfish-dev/file-viewer.git",
31
- "directory": "packages/renderers/archive"
30
+ "url": "git+https://github.com/flyfish-dev/file-viewer.git"
32
31
  },
33
32
  "homepage": "https://doc.file-viewer.app/guide/on-demand-renderers",
34
33
  "bugs": {
@@ -50,28 +49,38 @@
50
49
  "./package.json": "./package.json"
51
50
  },
52
51
  "files": [
53
- "dist",
52
+ "dist/archive.d.ts",
53
+ "dist/archive.js",
54
+ "dist/archiveCache.d.ts",
55
+ "dist/archiveCache.js",
56
+ "dist/archiveFallback.d.ts",
57
+ "dist/archiveFallback.js",
58
+ "dist/archiveLimits.d.ts",
59
+ "dist/archiveLimits.js",
60
+ "dist/archiveShared.d.ts",
61
+ "dist/archiveShared.js",
62
+ "dist/comicBook.d.ts",
63
+ "dist/comicBook.js",
64
+ "dist/index.d.ts",
65
+ "dist/index.js",
66
+ "dist/shapefileBundle.d.ts",
67
+ "dist/shapefileBundle.js",
54
68
  "file-viewer.capability.json",
55
- "README.md",
69
+ "LICENSE",
56
70
  "README.en.md",
57
- "LICENSE"
71
+ "README.md"
58
72
  ],
59
73
  "dependencies": {
60
- "@file-viewer/core": "3.1.2",
74
+ "@file-viewer/core": "3.2.0",
61
75
  "jszip": "3.10.2",
62
76
  "libarchive.js": "^2.0.2"
63
77
  },
64
- "devDependencies": {
65
- "typescript": "^6.0.3"
66
- },
67
78
  "fileViewer": {
68
- "capabilityManifest": "./file-viewer.capability.json"
79
+ "capabilityManifest": "./file-viewer.capability.json",
80
+ "distribution": {
81
+ "schemaVersion": 1,
82
+ "mode": "runtime-only"
83
+ }
69
84
  },
70
- "license": "Apache-2.0",
71
- "scripts": {
72
- "build": "tsc -b tsconfig.json",
73
- "type-check": "tsc -b tsconfig.json",
74
- "verify:github-101": "pnpm build && node scripts/verify-github-101.mjs",
75
- "verify:github-148": "pnpm build && node scripts/verify-github-148.mjs"
76
- }
77
- }
85
+ "license": "Apache-2.0"
86
+ }