本文整理汇总了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();
}
示例2: function
fs.writeFile(tempFileName, text, { encoding: 'utf8' }, function (err) {
fs.stat(tempFileName, function (err, stats) {
fs.unlink(tempFileName, function () {
callback(stats.size);
});
});
});
示例3: resolve
return new Promise<fs.Stats>((resolve, reject) => {
fs.stat(path, (err, stats) => {
if (err) return reject(err);
resolve(stats);
});
});
示例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();
});
示例5: Promise
return new Promise((resolve, reject) => {
const test = `${ viewDir }/${ filename }`;
stat(test, (err, res) => {
if (err) resolve(false);
resolve(true);
});
});
示例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);
}
});
}
示例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)
});
}
});
}
示例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);
});
});
});
});
示例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);
}
}
);
}
示例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);
});
}