mirror of
https://github.com/2234839/web-font.git
synced 2026-11-18 14:40:19 +08:00
- 慢路径 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)减少冷路径裁剪量
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
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);
|
||
},
|
||
});
|