MCPcopy
hub / github.com/ZToolsCenter/ZTools / getFileIconAsBase64

Function getFileIconAsBase64

src/main/core/iconProtocol.ts:94–108  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

92 * 支持文件路径或文件扩展名(如 ".txt"
93 */
94export async function getFileIconAsBase64(filePath: string): Promise<string> {
95 // 命中内存缓存(刷新 LRU 顺序)
96 const cached = iconMemoryCache.get(filePath)
97 if (cached) {
98 setIconCache(filePath, cached)
99 return `data:image/png;base64,${cached.toString('base64')}`
100 }
101
102 const buffer = await extractIconQueued(filePath)
103
104 // 写入内存缓存
105 setIconCache(filePath, buffer)
106
107 return `data:image/png;base64,${buffer.toString('base64')}`
108}
109
110/**
111 * 在指定 session 中注册 ztools-icon:// 协议 handler

Callers 1

setupIPCMethod · 0.90

Calls 3

setIconCacheFunction · 0.85
extractIconQueuedFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected