mirror of
https://github.com/2234839/web-font.git
synced 2026-09-04 23:02:27 +08:00
- 修复 fonteditor-core 模块声明(添加 FontEditor 命名空间、FontType 类型、SubsetOptions 接口) - 修复 llrt.ts 中 mkdir 和 rm 方法的返回类型问题 - 修复 tcp_server.ts 中 chunk 类型问题(添加 Buffer 类型检查和转换) - 修复 font_detail.ts 中缺失的 ORIGIN 导入 - 修复 subset.ts 中 subsetQueueTimeoutSeconds 的导入 - 为 Font 类添加 optimize() 和 write() 方法声明
45 lines
1.3 KiB
TypeScript
45 lines
1.3 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);
|
||
return { ...r, 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);
|
||
},
|
||
});
|