崮生(子虚) fe61bace16 fix: 修复所有 TypeScript 类型错误
- 修复 fonteditor-core 模块声明(添加 FontEditor 命名空间、FontType 类型、SubsetOptions 接口)
- 修复 llrt.ts 中 mkdir 和 rm 方法的返回类型问题
- 修复 tcp_server.ts 中 chunk 类型问题(添加 Buffer 类型检查和转换)
- 修复 font_detail.ts 中缺失的 ORIGIN 导入
- 修复 subset.ts 中 subsetQueueTimeoutSeconds 的导入
- 为 Font 类添加 optimize() 和 write() 方法声明
2026-08-15 07:38:57 +08:00

45 lines
1.3 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);
return { ...r, isDirectory: () => r.isDirectory() };
},
readFile(path) {
return readFile(path);
},
writeFile(path, data) {
return writeFile(path, data);
},
/**
* readdir 返回 { name, isFile } 适配对象
*
* 不用 withFileTypesLLRT 的 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);
},
});