當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fs.stat函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。