崮生(子虚) 1ffb1632b2 glyph-match 重构: 锚点索引+聚类剪枝+串行事件收集, 修复响应双 header 截断
- 慢路径 subset(查询字+锚点字) 顺带建 .gidx, 冷启动 39.75s→0.43s
- 去 async generator/worker 池/流式 pipeTo: LLRT 下非确定性饿死/segfault
- eventsCache(fontPath+查询签名 LRU64): 重复查询免裁剪, 稳态 42ms
- server 层 _bodyBytes 通道: header+body 单帧写回 + Content-Length
- 修复 bodyBytes 分支头部双写导致响应尾部截断(done 事件丢失)
- tcp 层 fire-and-forget write, close 只 end 不 destroy(保写缓冲)
- 慢路径并发度 GLYPH_MATCH_SLOW_CONCURRENCY 可配(默认1)
- 聚类排序+剪枝(PRUNE_MARGIN=0.35)减少冷路径裁剪量
2026-11-02 20:26:58 +08:00

46 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { implInterface } from "../interface";
import { stat as fsStat, readFile, writeFile, readdir as fsReaddir, mkdir, unlink, rm } from "fs/promises";
implInterface({
async stat(path) {
const r = await fsStat(path);
/** Stats 的 isFile/isDirectory 在原型上,{...r} 展开会丢失,必须显式包装 */
return { ...r, isFile: () => r.isFile(), isDirectory: () => r.isDirectory() };
},
readFile(path) {
return readFile(path);
},
writeFile(path, data) {
return writeFile(path, data);
},
/**
* readdir 返回 { name, isFile } 适配对象
*
* 不用 withFileTypes:LLRT 的 fs.readdir 不支持该选项,
* 返回的是纯字符串数组而非 Dirent 对象,调用 entry.isFile() 会抛 TypeError。
* 统一用 stat 判断,Node 和 LLRT 都兼容。
*/
async readdir(path) {
const names = await fsReaddir(path);
const results: { isFile: () => boolean; isDirectory: () => boolean; name: string }[] = [];
for (const name of names) {
try {
const s = await fsStat(path + "/" + name);
results.push({ name, isFile: () => s.isFile(), isDirectory: () => s.isDirectory() });
} catch {
/** stat 失败(符号链接断裂等)跳过 */
}
}
return results;
},
async mkdir(path) {
await mkdir(path, { recursive: true });
},
unlink(path) {
return unlink(path);
},
rm(path) {
return rm(path);
},
});