mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 14:31:22 +00:00
refactor(zip): reuse the textual view format predicate (#15952)
This commit is contained in:
1 parent
3f33f1411a
commit
6932f97bf4
1 file changed
+5
-14
@@ -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<JsonValue, string> => {
|
||||
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<JsonValue> = 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<string, JsonValue>,
|
||||
@@ -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";
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user