From 6932f97bf466ce2da8ab652f7c5ad4a3cfa8aa6a Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Wed, 2 Dec 2026 21:10:47 +0800 Subject: [PATCH] refactor(zip): reuse the textual view format predicate (#15952) --- src/domain/desktop/zipView.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/domain/desktop/zipView.ts b/src/domain/desktop/zipView.ts index 801233d3edb..e4150cb39e3 100644 --- a/src/domain/desktop/zipView.ts +++ b/src/domain/desktop/zipView.ts @@ -2,6 +2,7 @@ import type { JsonValue } from "../jsonValue.js"; import { err, ok, type Result } from "../result.js"; import { detectStateFormat, + isTextualFormat, textualView, type DesktopStateFormat, } from "./stateFormats.js"; @@ -66,12 +67,8 @@ const entryView = ( bytes: Uint8Array, policy: DesktopViewPolicy, ): Result => { + if (isTextualFormat(format)) return textualView(format, bytes, policy); switch (format) { - case "text": - case "json": - case "keyfile": - case "xml": - return textualView(format, bytes, policy); case "sqlite": return err("a SQLite database inside an archive is not read"); case "dconf": @@ -137,14 +134,6 @@ export const zipEntryAt = ( return isRecord(entry.value) ? entry.value : undefined; }; -/** Formats an entry's view is read in; any other entry's `view` is `null` for want of one. */ -const VIEW_FORMATS: ReadonlySet = new Set([ - "text", - "json", - "keyfile", - "xml", -]); - /** Why an entry has no view a check can read: binary, unread, or of a format with none; undefined when it has one. */ export const entryWithoutView = ( entry: Record, @@ -152,7 +141,9 @@ export const entryWithoutView = ( if (typeof entry.view_error === "string") return `has no view: ${entry.view_error}`; if (entry.format === "binary") return "is binary and has no view"; - return VIEW_FORMATS.has(entry.format ?? null) ? undefined : "has no view"; + return typeof entry.format === "string" && isTextualFormat(entry.format) + ? undefined + : "has no view"; }; /**