summaryrefslogtreecommitdiff
path: root/lib/fs.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fs.js')
-rw-r--r--lib/fs.js29
1 files changed, 11 insertions, 18 deletions
diff --git a/lib/fs.js b/lib/fs.js
index 2de5f8dd6e..85c939cc4a 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -43,7 +43,7 @@ const {
} = errors.codes;
const { Readable, Writable } = require('stream');
const EventEmitter = require('events');
-const { FSReqWrap, statValues } = binding;
+const { FSReqWrap, statValues, kFsStatsFieldsLength } = binding;
const { FSEvent } = process.binding('fs_event_wrap');
const internalFS = require('internal/fs');
const { getPathFromURL } = require('internal/url');
@@ -56,7 +56,8 @@ const {
nullCheck,
preprocessSymlinkDestination,
Stats,
- statsFromValues,
+ getStatsFromBinding,
+ getStatsFromGlobalBinding,
stringToFlags,
stringToSymlinkType,
toUnixTimestamp,
@@ -145,9 +146,9 @@ function makeStatsCallback(cb) {
throw new ERR_INVALID_CALLBACK();
}
- return function(err) {
+ return function(err, stats) {
if (err) return cb(err);
- cb(err, statsFromValues());
+ cb(err, getStatsFromBinding(stats));
};
}
@@ -891,7 +892,7 @@ fs.fstatSync = function(fd) {
const ctx = { fd };
binding.fstat(fd, undefined, ctx);
handleErrorFromBinding(ctx);
- return statsFromValues();
+ return getStatsFromGlobalBinding();
};
fs.lstatSync = function(path) {
@@ -900,7 +901,7 @@ fs.lstatSync = function(path) {
const ctx = { path };
binding.lstat(pathModule.toNamespacedPath(path), undefined, ctx);
handleErrorFromBinding(ctx);
- return statsFromValues();
+ return getStatsFromGlobalBinding();
};
fs.statSync = function(path) {
@@ -909,7 +910,7 @@ fs.statSync = function(path) {
const ctx = { path };
binding.stat(pathModule.toNamespacedPath(path), undefined, ctx);
handleErrorFromBinding(ctx);
- return statsFromValues();
+ return getStatsFromGlobalBinding();
};
fs.readlink = function(path, options, callback) {
@@ -1420,15 +1421,6 @@ function emitStop(self) {
self.emit('stop');
}
-function statsFromPrevValues() {
- return new Stats(statValues[14], statValues[15], statValues[16],
- statValues[17], statValues[18], statValues[19],
- statValues[20] < 0 ? undefined : statValues[20],
- statValues[21], statValues[22],
- statValues[23] < 0 ? undefined : statValues[23],
- statValues[24], statValues[25], statValues[26],
- statValues[27]);
-}
function StatWatcher() {
EventEmitter.call(this);
@@ -1439,13 +1431,14 @@ function StatWatcher() {
// the sake of backwards compatibility
var oldStatus = -1;
- this._handle.onchange = function(newStatus) {
+ this._handle.onchange = function(newStatus, stats) {
if (oldStatus === -1 &&
newStatus === -1 &&
statValues[2/* new nlink */] === statValues[16/* old nlink */]) return;
oldStatus = newStatus;
- self.emit('change', statsFromValues(), statsFromPrevValues());
+ self.emit('change', getStatsFromBinding(stats),
+ getStatsFromBinding(stats, kFsStatsFieldsLength));
};
this._handle.onstop = function() {