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


TypeScript fs.access函数代码示例

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


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

示例1: next

    ({ parseAscii, parseNative }: {
      parseAscii: boolean;
      parseNative: boolean;
    }, next: NodeBack) => {
      // initialise ascii flag
      parse.setOptions({
        ascii: parseAscii,
        native: parseNative,
      });

      // always build on startup if in dev mode
      if (nconf.any('build_emoji', 'BUILD_EMOJI')) {
        next(null, true);
        return;
      }

      // otherwise, build if never built before
      access(tableFile, (err) => {
        if (err && err.code !== 'ENOENT') {
          next(err);
          return;
        }

        next(null, !!err);
      });
    },
开发者ID:julianlam,项目名称:nodebb-plugin-emoji,代码行数:26,代码来源:index.ts

示例2: cacheAndDeliver

const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => {
    // Local variables
    let lookup = path.basename(decodeURI(req.url)) || 'index.html';
    let filePath = `${__dirname}/../content/${lookup}`

    // fs.exists had deprecated. Please use fs.stat() or fs.access()
    fs.access(filePath, (err: NodeJS.ErrnoException) => {

        // Check file
        console.log(err ? `${filePath} doesn't exist` : `${filePath} is there`);

        // Response with 404
        if (Boolean(err)) {
            res.writeHead(404);
            res.end('Page not Found!');
            return;
        }

        // Read file when existed
        cacheAndDeliver(filePath, (err: NodeJS.ErrnoException, data: Buffer) => {
            // Content not found
            if (err) { res.writeHead(500); res.end('ServerError!'); return; }

            // Content can be found
            let headers = { 'Content-type': mimeTypes[path.extname(lookup)] };
            res.writeHead(200, headers);
            res.end(data);
        });
    });
}).listen(8080, () => {
开发者ID:TonyPythoneer,项目名称:node-cookbook,代码行数:30,代码来源:app.ts

示例3: test

        test('should create the JSON File', done => {
            fs.access(testFile1 + ".json", fs.constants.R_OK, function (err) {
                expect(err).toBeNull()
                done()
            })

        })
开发者ID:Belphemur,项目名称:node-json-db,代码行数:7,代码来源:02-jsondb.test.ts

示例4: access

        return new Promise<boolean>(resolve => {
            access(path, err => {
                const pathExists = !err;

                resolve(pathExists);
            });
        });
开发者ID:KalitaAlexey,项目名称:RustyCode,代码行数:7,代码来源:FileSystem.ts

示例5: Promise

        return new Promise(resolve => {
            access(path, e => {
                // A path exists if there is no error
                const pathExists = !e;

                resolve(pathExists);
            });
        });
开发者ID:KalitaAlexey,项目名称:RustyCode,代码行数:8,代码来源:current_working_directory_manager.ts

示例6: Promise

  return new Promise(resolve => {
    const dir = path.resolve(__dirname, `../src/topics/${topic}`)

    fs.access(dir, fs.constants.F_OK, async err => {
      if (err) return resolve(false)
      return resolve(true)
    })
  })
开发者ID:jeremyboles,项目名称:jeremyboles.com,代码行数:8,代码来源:import.ts

示例7: Promise

 return new Promise((resolve, reject) => {
   fs.access(file, fs.constants.W_OK, (err) => {
     if (err) {
       resolve(false);
     }
     resolve(true);
   });
 });
开发者ID:piotrwitek,项目名称:jspm-hmr,代码行数:8,代码来源:init.ts

示例8: Promise

 return new Promise((resolve, reject) => {
   fs.access(folder, fs.constants.W_OK, (err) => {
     if (err) {
       reject({message: 'Error during getting write access to temp folder', error: err.toString()});
     }
   });
   resolve();
 });
开发者ID:bpatrik,项目名称:PiGallery2,代码行数:8,代码来源:ConfigDiagnostics.ts


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