alloc / alloc/jumpgen

Add `fs.typeof` method

未关闭
#11 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
good first issue help wanted
主要语言
TypeScript
星标
22
派生
1
PR 合并指标
30 天内没有已合并 PR

描述

It returns the path type according to its on-disk representation.

Possible results include: `file`, `directory`, `symlink`, `socket`, `fifo`, `characterDevice`, `blockDevice`

```ts
// The path argument may be absolute or relative to the root directory.
fs.typeof('foo')
```

The best use case for this is a `switch` statement.

```ts
switch (fs.typeof(path)) {
case 'file':
// ...
break

case 'directory':
// ...
break

default:
throw new Error('unsupported file type')
}
```

This is better than using `fs.stat` or `fs.lstat`, because `change` events don't need to be watched for like they do with those methods. Just need to use the `existenceWatcher`, I think.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。