MCPcopy
hub / github.com/codedogQBY/ReadAny / loadFileAsBlob

Function loadFileAsBlob

packages/app/src/components/reader/ReaderView.tsx:102–120  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

100
101// --- Tauri file loading ---
102async function loadFileAsBlob(filePath: string): Promise<Blob> {
103 // Resolve managed relative paths (e.g., "books/{id}.epub") to the active desktop library root.
104 const resolvedPath = await resolveDesktopDataPath(filePath);
105
106 try {
107 const { convertFileSrc } = await import("@tauri-apps/api/core");
108 const assetUrl =
109 resolvedPath.startsWith("asset://") || resolvedPath.startsWith("http")
110 ? resolvedPath
111 : convertFileSrc(resolvedPath);
112 const response = await fetch(assetUrl);
113 if (!response.ok) throw new Error(`fetch failed: ${response.status}`);
114 return await response.blob();
115 } catch {
116 const { readFile } = await import("@tauri-apps/plugin-fs");
117 const fileBytes = await readFile(resolvedPath);
118 return new Blob([fileBytes]);
119 }
120}
121
122// --- Blob cache ---
123const fileBlobCache = new Map<string, Blob>();

Callers 1

getCachedBlobFunction · 0.85

Calls 2

resolveDesktopDataPathFunction · 0.90
fetchFunction · 0.70

Tested by

no test coverage detected