当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript fs.fstatSync函数代码示例

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


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

示例1: it

 it('fs.write should work with util.promisify', (done: DoneFn) => {
   const promisifyWrite = util.promisify(write);
   const dest = __filename + 'write';
   const fd = openSync(dest, 'a');
   const stats = fstatSync(fd);
   const chunkSize = 512;
   const buffer = new Buffer(chunkSize);
   for (let i = 0; i < chunkSize; i++) {
     buffer[i] = 0;
   }
   // fd, buffer, offset, length, position, callback
   promisifyWrite(fd, buffer, 0, chunkSize, 0)
       .then(
           (value) => {
             expect(value.bytesWritten).toBe(chunkSize);
             closeSync(fd);
             unlinkSync(dest);
             done();
           },
           err => {
             closeSync(fd);
             unlinkSync(dest);
             fail(`should not be here with error: ${error}.`);
           });
 });
开发者ID:angular,项目名称:zone.js,代码行数:25,代码来源:fs.spec.ts

示例2: open

 protected open(filename: string): number {
   let fd = fs.openSync(filename, "r");
   this.fileMap[fd] = {
     size: fs.fstatSync(fd).size,
     pos: 0,
     name: filename,
   };
   return fd;
 }
开发者ID:YuJianrong,项目名称:nodejs-unrar,代码行数:9,代码来源:fileExtractor.ts

示例3: setTimeout

    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();
    });
开发者ID:zaidka,项目名称:genieacs,代码行数:14,代码来源:logger.ts

示例4: init

export function init(service, version): void {
  defaultMeta.hostname = os.hostname();
  defaultMeta.pid = process.pid;
  defaultMeta.name = `genieacs-${service}`;
  defaultMeta.version = version;

  LOG_FILE = config.get(`${service.toUpperCase()}_LOG_FILE`);
  ACCESS_LOG_FILE = config.get(`${service.toUpperCase()}_ACCESS_LOG_FILE`);

  if (LOG_FILE) {
    logStream = fs.createWriteStream(null, { fd: fs.openSync(LOG_FILE, "a") });
    logStat = fs.fstatSync(logStream.fd);
  }

  if (ACCESS_LOG_FILE) {
    accessLogStream = fs.createWriteStream(null, {
      fd: fs.openSync(ACCESS_LOG_FILE, "a")
    });
    accessLogStat = fs.fstatSync(accessLogStream.fd);
  }

  // Determine if logs are going to journald
  const JOURNAL_STREAM = process.env["JOURNAL_STREAM"];

  if (JOURNAL_STREAM) {
    const [dev, inode] = JOURNAL_STREAM.split(":").map(parseInt);

    LOG_SYSTEMD = logStat.dev === dev && logStat.ino === inode;
    ACCESS_LOG_SYSTEMD =
      accessLogStat.dev === dev && accessLogStat.ino === inode;
  }

  if (LOG_FILE || ACCESS_LOG_FILE)
    // Can't use setInterval as we need all workers to cehck at the same time
    setTimeout(reopen, REOPEN_EVERY - (Date.now() % REOPEN_EVERY)).unref();
}
开发者ID:zaidka,项目名称:genieacs,代码行数:36,代码来源:logger.ts

示例5: openSync

import { openSync, readSync, fstatSync, Stats } from 'fs';

let fileDescriptor: number;
try {
  fileDescriptor = openSync('hello.txt', 'r');
} catch (err) {
  console.log(`Couldn't open: ${err.message}`);
  process.exit(1);
}

let stat: Stats;
try {
  stat = fstatSync(fileDescriptor);
} catch (err) {
  console.log(`Couldn't get stat: ${err.message}`);
  process.exit(1);
}

const buffer = Buffer.alloc(stat.size);

try {
  readSync(fileDescriptor, buffer, 0, stat.size, null);
} catch (err) {
  console.log(`Couldn't read: ${err.message}`);
  process.exit(1);
}

let data: string;
try {
  data = buffer.toString();
} catch (err) {
开发者ID:Mercateo,项目名称:rust-for-node-developers,代码行数:31,代码来源:index.ts

示例6: reopen

  /* eslint-disable-next-line @typescript-eslint/no-namespace */
  namespace NodeJS {
    export interface WritableStream {
      fd?: number;
    }
  }
}

declare module "fs" {
  interface WriteStream {
    fd?: number;
  }
}

let logStream = fs.createWriteStream(null, { fd: process.stderr.fd });
let logStat = fs.fstatSync(logStream.fd);
let accessLogStream = fs.createWriteStream(null, { fd: process.stdout.fd });
let accessLogStat = fs.fstatSync(accessLogStream.fd);

// 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, {
开发者ID:zaidka,项目名称:genieacs,代码行数:31,代码来源:logger.ts

示例7: openSync

import { openSync, readSync, fstatSync } from 'fs';

let file;
try {
  file = openSync('hello.txt', 'r');
} catch (err) {
  console.log(`Couldn't open: ${err.message}`);
  process.exit(1);
}

let stat;
try {
  stat = fstatSync(file);
} catch (err) {
  console.log(`Couldn't get stat: ${err.message}`);
  process.exit(1);
}

const buffer = new Buffer(stat.size);

try {
  readSync(file, buffer, 0, stat.size, null);
} catch (err) {
  console.log(`Couldn't read: ${err.message}`);
  process.exit(1);
}

let data;
try {
  data = buffer.toString();
} catch (err) {
开发者ID:allyjweir,项目名称:rust-for-node-developers,代码行数:31,代码来源:index.ts


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