欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

node.js中的fs.realpathSync方法使用說(shuō)明

 更新時(shí)間:2014年12月16日 09:26:30   投稿:junjie  
這篇文章主要介紹了node.js中的fs.realpathSync方法使用說(shuō)明,本文介紹了fs.realpathSync的方法說(shuō)明、語(yǔ)法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下

方法說(shuō)明:

同步版的 fs.realpath()

語(yǔ)法:

復(fù)制代碼 代碼如下:

fs.realpathSync(path, [cache])

由于該方法屬于fs模塊,使用前需要引入fs模塊(var fs= require(“fs”) )

接收參數(shù):

path                             路徑

cache                           可選,一個(gè)文字的映射路徑可用于強(qiáng)制一個(gè)特定的路徑解決或避免額外的fs.stat需要知道真正的路徑對(duì)象。

例子:

復(fù)制代碼 代碼如下:

var fs = require('fs');
 
// 點(diǎn)號(hào)表示當(dāng)前文件所在路徑
var str = fs.realpathSync('.');
console.log(str);

源碼:

復(fù)制代碼 代碼如下:

fs.realpathSync = function realpathSync(p, cache) {
  // make p is absolute
  p = pathModule.resolve(p);
  if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
    return cache[p];
  }
  var original = p,
      seenLinks = {},
      knownHard = {};
  // current character position in p
  var pos;
  // the partial path so far, including a trailing slash if any
  var current;
  // the partial path without a trailing slash (except when pointing at a root)
  var base;
  // the partial path scanned in the previous round, with slash
  var previous;
  start();
  function start() {
    // Skip over roots
    var m = splitRootRe.exec(p);
    pos = m[0].length;
    current = m[0];
    base = m[0];
    previous = '';
    // On windows, check that the root exists. On unix there is no need.
    if (isWindows && !knownHard[base]) {
      fs.lstatSync(base);
      knownHard[base] = true;
    }
  }
  // walk down the path, swapping out linked pathparts for their real
  // values
  // NB: p.length changes.
  while (pos < p.length) {
    // find the next part
    nextPartRe.lastIndex = pos;
    var result = nextPartRe.exec(p);
    previous = current;
    current += result[0];
    base = previous + result[1];
    pos = nextPartRe.lastIndex;
    // continue if not a symlink
    if (knownHard[base] || (cache && cache[base] === base)) {
      continue;
    }
    var resolvedLink;
    if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
      // some known symbolic link. no need to stat again.
      resolvedLink = cache[base];
    } else {
      var stat = fs.lstatSync(base);
      if (!stat.isSymbolicLink()) {
        knownHard[base] = true;
        if (cache) cache[base] = base;
        continue;
      }
      // read the link if it wasn't read before
      // dev/ino always return 0 on windows, so skip the check.
      var linkTarget = null;
      if (!isWindows) {
        var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
        if (seenLinks.hasOwnProperty(id)) {
          linkTarget = seenLinks[id];
        }
      }
      if (util.isNull(linkTarget)) {
        fs.statSync(base);
        linkTarget = fs.readlinkSync(base);
      }
      resolvedLink = pathModule.resolve(previous, linkTarget);
      // track this, if given a cache.
      if (cache) cache[base] = resolvedLink;
      if (!isWindows) seenLinks[id] = linkTarget;
    }
    // resolve the link, then start over
    p = pathModule.resolve(resolvedLink, p.slice(pos));
    start();
  }
  if (cache) cache[original] = p;
  return p;
};

相關(guān)文章

  • Node.js中路徑處理模塊path詳解

    Node.js中路徑處理模塊path詳解

    相信大家都知道在nodejs中,path是個(gè)使用頻率很高,但卻讓人又愛(ài)又恨的模塊。因?yàn)椴糠治臋n說(shuō)的不夠清晰,還有部分因?yàn)榻涌诘钠脚_(tái)差異性。本文就給大家詳細(xì)介紹下關(guān)于Node.js中的路徑處理模塊path,希望能對(duì)大家學(xué)習(xí)或者使用模塊path有所幫助,下面來(lái)一起看看吧。
    2016-11-11
  • node.js中實(shí)現(xiàn)雙重身份驗(yàn)證機(jī)制的方法詳解

    node.js中實(shí)現(xiàn)雙重身份驗(yàn)證機(jī)制的方法詳解

    雙重身份驗(yàn)證(Two-factor?authentication)是一種安全機(jī)制,它要求用戶(hù)提供兩種不同的身份驗(yàn)證因素來(lái)訪問(wèn)他們的帳戶(hù),下面我們就來(lái)學(xué)習(xí)一下如何使用speakeasy在nodejs中實(shí)現(xiàn)雙重身份驗(yàn)證吧
    2023-10-10
  • koa+jwt實(shí)現(xiàn)token驗(yàn)證與刷新功能

    koa+jwt實(shí)現(xiàn)token驗(yàn)證與刷新功能

    這篇文章主要介紹了koa+jwt實(shí)現(xiàn)token驗(yàn)證與刷新功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-05-05
  • Node.js基礎(chǔ)入門(mén)之path模塊,url模塊,http模塊使用詳解

    Node.js基礎(chǔ)入門(mén)之path模塊,url模塊,http模塊使用詳解

    這篇文章主要為大家介紹了Node.js中的三個(gè)模塊(path、url、http)的使用詳解,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下
    2022-03-03
  • 輕松創(chuàng)建nodejs服務(wù)器(3):代碼模塊化

    輕松創(chuàng)建nodejs服務(wù)器(3):代碼模塊化

    這篇文章主要介紹了輕松創(chuàng)建nodejs服務(wù)器(3):代碼模塊化,本文是對(duì)第一節(jié)的例子作了封裝,需要的朋友可以參考下
    2014-12-12
  • Node.js中常用設(shè)計(jì)模式的使用方法總結(jié)

    Node.js中常用設(shè)計(jì)模式的使用方法總結(jié)

    設(shè)計(jì)模式是由經(jīng)驗(yàn)豐富的程序員在日積月累中抽象出的用以解決通用問(wèn)題的可復(fù)用解決方案,它提供了標(biāo)準(zhǔn)化的代碼設(shè)計(jì)方案提升開(kāi)發(fā)體驗(yàn),本文主要來(lái)和大家討論一下Node.js中設(shè)計(jì)模式的重要性并提供一些代碼示例,感興趣的可以了解下
    2023-10-10
  • 解決npm?i?報(bào)錯(cuò)以及python安裝卡住的問(wèn)題

    解決npm?i?報(bào)錯(cuò)以及python安裝卡住的問(wèn)題

    這篇文章主要介紹了解決npm?i?報(bào)錯(cuò)以及python安裝卡住的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • node鏈接mongodb數(shù)據(jù)庫(kù)的方法詳解【阿里云服務(wù)器環(huán)境ubuntu】

    node鏈接mongodb數(shù)據(jù)庫(kù)的方法詳解【阿里云服務(wù)器環(huán)境ubuntu】

    這篇文章主要介紹了node鏈接mongodb數(shù)據(jù)庫(kù)的方法,結(jié)合實(shí)例形式分析了nodejs基于阿里云服務(wù)器環(huán)境ubuntu下實(shí)現(xiàn)連接MongoDB數(shù)據(jù)庫(kù)的相關(guān)操作技巧,需要的朋友可以參考下
    2019-03-03
  • nodejs中方法和模塊用法示例

    nodejs中方法和模塊用法示例

    這篇文章主要介紹了nodejs中方法和模塊用法,結(jié)合實(shí)例形式分析了nodejs方法與模塊的定義及使用方法,需要的朋友可以參考下
    2018-12-12
  • nodeJS服務(wù)器的創(chuàng)建和重新啟動(dòng)的實(shí)現(xiàn)方法

    nodeJS服務(wù)器的創(chuàng)建和重新啟動(dòng)的實(shí)現(xiàn)方法

    今天小編就為大家分享一篇nodeJS服務(wù)器的創(chuàng)建和重新啟動(dòng)的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05

最新評(píng)論