<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        node.js中的fs.realpath方法使用說明_node.js

        來源:懂視網 責編:小采 時間:2020-11-27 21:30:15
        文檔

        node.js中的fs.realpath方法使用說明_node.js

        node.js中的fs.realpath方法使用說明_node.js:方法說明: 獲取真實路徑。 可以使用process.cwd解決相對路徑。 語法: 代碼如下: fs.realpath(path, [cache], [callback(err , resolvedPath)]) 由于該方法屬于fs模塊,使用前需要引入fs模塊(var fs= require(fs) ) 接收參數
        推薦度:
        導讀node.js中的fs.realpath方法使用說明_node.js:方法說明: 獲取真實路徑。 可以使用process.cwd解決相對路徑。 語法: 代碼如下: fs.realpath(path, [cache], [callback(err , resolvedPath)]) 由于該方法屬于fs模塊,使用前需要引入fs模塊(var fs= require(fs) ) 接收參數

        方法說明:

        獲取真實路徑。

        可以使用process.cwd解決相對路徑。

        語法:

        代碼如下:
        fs.realpath(path, [cache], [callback(err , resolvedPath)])

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

        接收參數:

        path 路徑

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

        callback 回調

        err 異常

        resolvedPath 真實地址

        例子:

        代碼如下:
        var cache = {'/etc':'/private/etc'};
        fs.realpath('/etc/passwd', cache, function (err, resolvedPath) {
        if (err) throw err;
        console.log(resolvedPath);
        });

        源碼:

        代碼如下:
        fs.realpath = function realpath(p, cache, cb) {
        if (!util.isFunction(cb)) {
        cb = maybeCallback(cache);
        cache = null;
        }
        // make p is absolute
        p = pathModule.resolve(p);
        if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
        return process.nextTick(cb.bind(null, null, 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.lstat(base, function(err) {
        if (err) return cb(err);
        knownHard[base] = true;
        LOOP();
        });
        } else {
        process.nextTick(LOOP);
        }
        }
        // walk down the path, swapping out linked pathparts for their real
        // values
        function LOOP() {
        // stop if scanned past end of path
        if (pos >= p.length) {
        if (cache) cache[original] = p;
        return cb(null, p);
        }
        // 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)) {
        return process.nextTick(LOOP);
        }
        if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
        // known symbolic link. no need to stat again.
        return gotResolvedLink(cache[base]);
        }
        return fs.lstat(base, gotStat);
        }
        function gotStat(err, stat) {
        if (err) return cb(err);
        // if not a symlink, skip to the next path part
        if (!stat.isSymbolicLink()) {
        knownHard[base] = true;
        if (cache) cache[base] = base;
        return process.nextTick(LOOP);
        }
        // stat & read the link if not read before
        // call gotTarget as soon as the link target is known
        // dev/ino always return 0 on windows, so skip the check.
        if (!isWindows) {
        var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
        if (seenLinks.hasOwnProperty(id)) {
        return gotTarget(null, seenLinks[id], base);
        }
        }
        fs.stat(base, function(err) {
        if (err) return cb(err);
        fs.readlink(base, function(err, target) {
        if (!isWindows) seenLinks[id] = target;
        gotTarget(err, target);
        });
        });
        }
        function gotTarget(err, target, base) {
        if (err) return cb(err);
        var resolvedLink = pathModule.resolve(previous, target);
        if (cache) cache[base] = resolvedLink;
        gotResolvedLink(resolvedLink);
        }
        function gotResolvedLink(resolvedLink) {
        // resolve the link, then start over
        p = pathModule.resolve(resolvedLink, p.slice(pos));
        start();
        }
        };

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        node.js中的fs.realpath方法使用說明_node.js

        node.js中的fs.realpath方法使用說明_node.js:方法說明: 獲取真實路徑。 可以使用process.cwd解決相對路徑。 語法: 代碼如下: fs.realpath(path, [cache], [callback(err , resolvedPath)]) 由于該方法屬于fs模塊,使用前需要引入fs模塊(var fs= require(fs) ) 接收參數
        推薦度:
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 免费的黄色网页在线免费观看| 成人免费在线观看网站| 黄色网页免费观看| 亚洲人成人77777网站不卡| 亚洲色婷婷一区二区三区| 日产乱码一卡二卡三免费| 91精品全国免费观看含羞草| 国产久爱免费精品视频| 欧美日韩亚洲精品| 亚洲日韩一区二区三区| 亚洲高清无在码在线电影不卡| 中文亚洲AV片在线观看不卡| 国产jizzjizz视频全部免费| 久久久久久99av无码免费网站 | 亚洲精品视频在线免费| a毛片在线免费观看| 一级一级毛片免费播放| 高h视频在线免费观看| 国产精品无码亚洲精品2021| 亚洲一级毛片在线播放| 亚洲国产高清在线精品一区| 亚洲国产精品热久久| 亚洲AV一宅男色影视| 亚洲啪啪AV无码片| 亚洲一区无码中文字幕 | 中文在线免费视频| 曰韩无码AV片免费播放不卡| 羞羞漫画小舞被黄漫免费| 亚洲AV成人无码网站| 亚洲精品无码高潮喷水A片软| 亚洲一区二区三区国产精华液| 亚洲av无码不卡久久| 亚洲乱码在线播放| 亚洲AV成人无码天堂| 国产色在线|亚洲| 亚洲综合av一区二区三区| 亚洲欧洲无码一区二区三区| 亚洲精品乱码久久久久久蜜桃图片| 亚洲色在线无码国产精品不卡| 亚洲精品宾馆在线精品酒店| 极品色天使在线婷婷天堂亚洲|