• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript fs.stat函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中fs.stat函数的典型用法代码示例。如果您正苦于以下问题:TypeScript stat函数的具体用法?TypeScript stat怎么用?TypeScript stat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了stat函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: reopen

// Reopen if original files have been moved (e.g. logrotate)
function reopen(): void {
  let counter = 1;

  if (LOG_FILE) {
    ++counter;
    fs.stat(LOG_FILE, (err, stat) => {
      if (err && !err.message.startsWith("ENOENT:")) throw err;

      if (!(stat && stat.dev === logStat.dev && stat.ino === logStat.ino)) {
        logStream.end();
        logStream = fs.createWriteStream(null, {
          fd: fs.openSync(LOG_FILE, "a")
        });
        logStat = fs.fstatSync(logStream.fd);
      }

      if (--counter === 0)
        setTimeout(reopen, REOPEN_EVERY - (Date.now() % REOPEN_EVERY)).unref();
    });
  }

  if (ACCESS_LOG_FILE) {
    ++counter;
    fs.stat(ACCESS_LOG_FILE, (err, stat) => {
      if (err && !err.message.startsWith("ENOENT:")) throw err;

      if (
        !(
          stat &&
          stat.dev === accessLogStat.dev &&
          stat.ino === accessLogStat.ino
        )
      ) {
        accessLogStream.end();
        accessLogStream = fs.createWriteStream(null, {
          fd: fs.openSync(ACCESS_LOG_FILE, "a")
        });
        accessLogStat = fs.fstatSync(accessLogStream.fd);
      }

      if (--counter === 0)
        setTimeout(reopen, REOPEN_EVERY - (Date.now() % REOPEN_EVERY)).unref();
    });
  }

  if (--counter === 0)
    setTimeout(reopen, REOPEN_EVERY - (Date.now() % REOPEN_EVERY)).unref();
}
开发者ID:zaidka,项目名称:genieacs,代码行数:49,代码来源:logger.ts


示例2: function

 fs.writeFile(tempFileName, text, { encoding: 'utf8' }, function (err) {
   fs.stat(tempFileName, function (err, stats) {
     fs.unlink(tempFileName, function () {
       callback(stats.size);
     });
   });
 });
开发者ID:codeandcats,项目名称:fast-clone,代码行数:7,代码来源:dataHelper.ts


示例3: resolve

    return new Promise<fs.Stats>((resolve, reject) => {
      fs.stat(path, (err, stats) => {

        if (err) return reject(err);
        resolve(stats);
      });
    });
开发者ID:chen-framework,项目名称:chen,代码行数:7,代码来源:filesystem.ts


示例4: function

		fs.mkdir(path, (err: any) => {
			console.log('making path');
			if (err && pflag) {
				// TODO: this is where we should check
				// if path has multiple components,
				// and if it does, attempt to create
				// each component.  For now just error
				// out.
				//process.stderr.write(err.message + '\n', finished);
				//return;
				let subdirs = path.split('/');
				console.log(subdirs);
				let subpath = '';
				for (let j = 0; j < subdirs.length; j++) {
					subpath += subdirs[j] + '/';
					fs.stat(subpath, function(oerr: any, stats: fs.Stats): void {
						// this never runs
						console.log("I never print");
						if (oerr) {
							console.log("ERRR");
							fs.mkdir(subpath, (ooerr: any) => {
								// too much fail. no more try.
								process.stderr.write(ooerr.message + '\n', finished);
								return;
							});
						}
					});
				}
			} else if (err) {
				code = 1;
				process.stderr.write(err.message + '\n', finished);
				return;
			}
			finished();
		});
开发者ID:kshitijSharma2014,项目名称:browsix,代码行数:35,代码来源:mkdir.ts


示例5: Promise

 return new Promise((resolve, reject) => {
   const test = `${ viewDir }/${ filename }`;
   stat(test, (err, res) => {
     if (err) resolve(false);
     resolve(true);
   });
 });
开发者ID:overlandjs,项目名称:overland-nunjucks,代码行数:7,代码来源:index.ts


示例6: stat

function stat(inputs: string[], output: NodeJS.WritableStream, code: number): void {
	'use strict';

	if (!inputs || !inputs.length) {
		process.exit(code);
		return;
	}

	let current = inputs[0];
	inputs = inputs.slice(1);

	if (!current) {
		// use setTimeout to avoid a deep stack as well as
		// cooperatively yield
		setTimeout(stat, 0, inputs, output, code);
		return;
	}

	fs.stat(current, function(err: any, stats: fs.Stats): void {
		if (err) {
			process.stderr.write('ERROR: ' + err, writeCompleted);
			return;
		}
		output.write(formatStats(current, stats), writeCompleted);

		function writeCompleted(): void {
			setTimeout(stat, 0, inputs, output, code);
		}
	});
}
开发者ID:anuragagarwal561994,项目名称:browsix,代码行数:30,代码来源:stat.ts


示例7: addRoutesInDir

// no callback as it doesn't really matter. we don't notify anything that we are done
function addRoutesInDir(baseDir, dir, router) {
  const fullDir = path.join(baseDir, dir);

  fs.stat(fullDir, function(err, stats) {
    if (err) {
      return;
    }

    if (stats.isDirectory()) {
      fs.readdir(fullDir, function(err, files) {
        if (err) {
          return;
        }

        files.forEach(function(file) {
          addRoutesInDir(baseDir, path.join(dir, file), router);
        });
      });
    } else {
      // make sure it ends in .dust
      if (dir.lastIndexOf('.dust') !== (dir.length - 5)) {
        return;
      }

      const isIndex = dir.lastIndexOf('/index.dust') === (dir.length - 11);
      const url = isIndex ? dir.substr(0, dir.length - 11) : dir.substr(0, dir.length - 5);

      router.get(url, function(req, res) {
        res.render(fullDir)
      });
    }
  });
}
开发者ID:HallM,项目名称:poc-fw2,代码行数:34,代码来源:prod-auto-routes.ts


示例8: _

			fs.exists(src, (exists) => {
				if (!exists) return finish(new Error('loadRepoProjectDefs not exists ' + src), ret);

				fs.stat(src, (err, stats) => {
					if (err) return finish(err, ret);
					if (!stats.isDirectory()) return finish(new Error('loadRepoProjectDefs not directory ' + src), ret);

					fs.readdir(src, (err, files:string[]) => {
						if (err) return finish(err, ret);

						files = _(files).filter((name) => {
							return extDef.test(name);
						});

						if (files.length == 0) {
							return finish(null, ret);
						}

						async.forEach(files, (name, callback:(err) => void) => {
							//src + '/' + file + '/' + sub;
							var tmp = path.join(src, name);
							fs.stat(tmp, (err, stats) => {
								if (err) return callback(err);
								if (stats.isDirectory()) return callback(null);

								//console.log('-> def ' + name);
								ret.push(new Def(project, name.replace(extDef, '')));
								callback(null);
							});
						}, (err) => {
							finish(err, ret);
						});
					});
				});
			});
开发者ID:Bartvds,项目名称:tsd-deftools,代码行数:35,代码来源:loader.ts


示例9: downloadPlayers

    function downloadPlayers(nextPlayer) {
        var numberOfPlayers = 550;
        if (nextPlayer > numberOfPlayers) {
            return;
        }

        fs.stat(
            repositoryDirectory + nextPlayer + ".json",
            (err, stats) => {

                var success = false;

                if (stats && stats.mtime && stats.mtime < today) {
                    downloadPlayer.download(nextPlayer);
                    success = true;
                }

                if(success) {
                    setTimeout(() => downloadPlayers(nextPlayer + 1), 1000);
                } else {
                    downloadPlayers(nextPlayer + 1);
                }
            }
        );
    }
开发者ID:epsom-software,项目名称:FantasyFootballStats,代码行数:25,代码来源:download.ts


示例10: cacheAndDeliver

function cacheAndDeliver(f: string,
                         cb: (err:NodeJS.ErrnoException, data: Buffer) => void) {
    fs.stat(f, (err, stats: fs.Stats) => {
        //
        if (err) { return console.log('Oh no!, Eror', err); }

        // Local variables
        let lastChanged: number = Date.parse(stats.ctime.toString())
        let isUpdated: boolean = (cache[f]) && lastChanged > cache[f].timestamp;

        // Check the file need to update or not
        if (!cache[f] || isUpdated) {
            fs.readFile(f, (err, data) => {
                console.log('loading ' + f + ' from file');
                cache[f] = { content: data, timestamp: Date.now() };
                cb(err, data);
                return;
            });
        }

        // Loading from cache
        console.log(`loading ${f} from cache`);
        cb(null, cache[f].content);
    });
}
开发者ID:TonyPythoneer,项目名称:node-cookbook,代码行数:25,代码来源:app.ts



注:本文中的fs.stat函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript fs.statSync函数代码示例发布时间:2022-05-25
下一篇:
TypeScript fs.rmdirSync函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap