當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。