本文整理汇总了TypeScript中fs.Stats类的典型用法代码示例。如果您正苦于以下问题:TypeScript Stats类的具体用法?TypeScript Stats怎么用?TypeScript Stats使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Stats类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: walk
export function walk(path: string, options: WalkOptions) {
let stats: Stats
try {
stats = (options.follow !== false ? statSync : lstatSync)(path)
} catch (e) {
options.error && options.error(e, path)
return
}
if (stats.isFile()) {
options.file && options.file(path, stats)
} else if (stats.isDirectory()) {
if (!options.dir || options.dir(path, stats) !== false) {
let entries: string[]
try {
entries = readdirSync(path)
} catch (e) {
options.error && options.error(e, path)
return
}
if (!options.walkDir || options.walkDir(path, entries, stats) !== false) {
for (const entry of entries) {
walk(join(path, entry), options)
}
}
}
} else {
options.other && options.other(path, stats)
}
}
开发者ID:tpack,项目名称:utilskit,代码行数:29,代码来源:fs.ts
示例2: findFile
function findFile(dir: string, fileName: string): string {
'use strict';
let children: string[] = fs.readdirSync(dir);
for (let i: number = 0; i < children.length; ++i) {
let path: string = dir + '/' + children[i];
let stat: Stats = fs.statSync(path);
if (stat.isFile()) {
if (children[i] === fileName) {
return path;
}
} else if (stat.isDirectory()) {
let result: string = findFile(path, fileName);
if (result) {
return result;
}
}
}
return undefined;
}
开发者ID:data9824,项目名称:SavannaTalk,代码行数:19,代码来源:main.ts
示例3: saveCachedResolution
async function saveCachedResolution (): Promise<FetchedPackage> {
const target = path.join(modules, spec.name)
const stat: Stats = await fs.lstat(target)
if (stat.isSymbolicLink()) {
const linkPath = await fs.readlink(target)
return save(path.resolve(linkPath, target))
}
return save(target)
async function save (fullpath: string): Promise<FetchedPackage> {
const data = await requireJson(path.join(fullpath, 'package.json'))
return {
fetchingPkg: Promise.resolve(data),
fetchingFiles: Promise.resolve(),
id: path.basename(fullpath),
fromCache: true,
path: fullpath,
abort: () => Promise.resolve(),
}
}
}
开发者ID:andreypopp,项目名称:pnpm,代码行数:21,代码来源:fetch.ts
示例4:
export const getFileType = (stats: Stats): FileType => {
return stats.isSymbolicLink() ? FileType.SymbolicLink :
stats.isFile() ? FileType.File :
stats.isDirectory() ? FileType.Directory :
stats.isBlockDevice() ? FileType.BlockDevice :
stats.isCharacterDevice() ? FileType.CharacterDevice :
stats.isFIFO() ? FileType.FIFO :
stats.isSocket() ? FileType.Socket :
FileType.Other;
};
开发者ID:Kuchasz,项目名称:smart-downloader,代码行数:10,代码来源:FileTypeAccessor.ts
示例5: safeLink
async function safeLink(existingPath: string, newPath: string, stat: Stats) {
try {
await fs.link(existingPath, newPath)
} catch (err) {
// shouldn't normally happen, but if the file was already somehow linked,
// the installation should not fail
if (err.code === 'EEXIST') {
return
}
// might happen if package contains a broken symlink, we don't fail on this
if (err.code === 'ENOENT' && stat.isSymbolicLink()) {
logger.warn({
message: `Broken symlink found: ${existingPath}`,
})
return
}
throw err
}
}
开发者ID:andreypopp,项目名称:pnpm,代码行数:19,代码来源:hardlinkDir.ts
示例6: get_listing
export async function get_listing(
path: string,
hidden: boolean = false
): Promise<ListingEntry[]> {
const dir = HOME + "/" + path;
const files: ListingEntry[] = [];
let name: string;
for (name of await callback(readdir, dir)) {
if (!hidden && name[0] === ".") {
continue;
}
let entry: ListingEntry;
try {
// I don't actually know if file can fail to be JSON-able with node.js -- is there
// even a string in Node.js that cannot be dumped to JSON? With python
// this definitely was a problem, but I can't find the examples now. Users
// sometimes create "insane" file names via bugs in C programs...
JSON.stringify(name);
entry = { name };
} catch (err) {
entry = { name: "????", error: "Cannot display bad binary filename. " };
}
let stats: Stats;
try {
stats = await callback(lstat, dir + "/" + entry.name);
if (stats.isSymbolicLink()) {
entry.issymlink = true;
try {
stats = await callback(stat, dir + "/" + entry.name);
} catch (err) {
// broken link -- just report info about the link itself...
}
}
entry.mtime = stats.mtime.valueOf() / 1000;
if (stats.isDirectory()) {
entry.isdir = true;
try {
const v = await callback(readdir, dir + "/" + entry.name);
if (hidden) {
entry.size = v.length;
} else {
// only count non-hidden files
entry.size = 0;
for (let x of v) {
if (x[0] != ".") {
entry.size += 1;
}
}
}
} catch (err) {
// just ignore -- no size info.
}
} else {
entry.size = stats.size;
}
} catch (err) {
entry.error = `${entry.error ? entry.error : ""}${err}`;
}
files.push(entry);
}
return files;
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:63,代码来源:directory-listing.ts
注:本文中的fs.Stats类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论