国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答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
主站蜘蛛池模板: 国产一区二区成人 | 亚洲精品国产字幕久久vr | 亚洲十欧美十日韩十国产 | 日本韩国一区 | 国产v精品成人免费视频400条 | 日本欧美国产精品第一页久久 | 国产精品va一区二区三区 | xx中文字幕乱偷avxx | 国产成人久久蜜一区二区 | 国产亚洲欧美另类一区二区三区 | 国产精品免费观看网站 | 亚洲视频免费一区 | 另类亚洲色图 | 久久精品国产国产精品四凭 | 亚洲欧美在线视频观看 | 日韩在线一区二区三区免费视频 | 一区二区三区高清不卡 | 国产精品免费精品自在线观看 | 国产精品成人一区二区1 | 亚洲精品在线播放 | 国产精品综合一区二区 | 国产欧美另类第一页 | 日韩在线资源 | 免费一区二区视频 | 国产123区在线视频观看 | 国产香蕉视频在线观看 | 欧美精品一二三 | 激情综合亚洲欧美日韩 | 国产欧美一区二区精品久久久 | 国产午夜视频在线观看 | 五月婷婷中文字幕 | 日韩精品视频免费观看 | 特一级大黄在线观看 | 亚洲综合一区二区精品久久 | 午夜精品一区二区三区免费视频 | 啪啪免费 | 中文字幕亚洲综合 | 国产人成久久久精品 | 一级毛片在线看在线播放 | 亚洲第一区视频在线观看 | 综合 欧美 国产 视频二区 |