Comparing version 4.1.0 to 4.2.0
# Change Log | ||
## 4.2.0 | ||
* Update fs.stat(), fs.lstat(), and fs.fstat() for Node 7.7+ (thanks @not-an-aardvark, see [#198][#198]) | ||
## 4.1.0 | ||
@@ -181,1 +185,2 @@ | ||
[#195]: https://github.com/tschaub/mock-fs/pull/195 | ||
[#198]: https://github.com/tschaub/mock-fs/pull/198 |
@@ -23,3 +23,3 @@ 'use strict'; | ||
function maybeCallback(callback, thisArg, func) { | ||
if (callback) { | ||
if (callback && (typeof callback === 'function' || typeof callback.oncomplete === 'function')) { | ||
var err = null; | ||
@@ -270,2 +270,26 @@ var val; | ||
/** | ||
* Fill a Float64Array with stat information | ||
* This is based on the internal FillStatsArray function in Node. | ||
* https://github.com/nodejs/node/blob/4e05952a8a75af6df625415db612d3a9a1322682/src/node_file.cc#L533 | ||
* @param {object} stats An object with file stats | ||
* @param {Float64Array} statValues A Float64Array where stat values should be inserted | ||
* @returns {void} | ||
*/ | ||
function fillStatsArray(stats, statValues) { | ||
statValues[0] = stats.dev; | ||
statValues[1] = stats.mode; | ||
statValues[2] = stats.nlink; | ||
statValues[3] = stats.uid; | ||
statValues[4] = stats.gid; | ||
statValues[5] = stats.rdev; | ||
statValues[6] = stats.blksize; | ||
statValues[7] = stats.ino; | ||
statValues[8] = stats.size; | ||
statValues[9] = stats.blocks; | ||
statValues[10] = +stats.atime; | ||
statValues[11] = +stats.mtime; | ||
statValues[12] = +stats.ctime; | ||
statValues[13] = +stats.birthtime; | ||
} | ||
@@ -275,3 +299,4 @@ /** | ||
* @param {string} filepath Path. | ||
* @param {function(Error, Stats)} callback Callback (optional). | ||
* @param {function(Error, Stats)|Float64Array} callback Callback (optional). In Node 7.7.0+ this will be a Float64Array | ||
* that should be filled with stat values. | ||
* @return {Stats|undefined} Stats or undefined (if sync). | ||
@@ -289,3 +314,12 @@ */ | ||
} | ||
return new Stats(item.getStats()); | ||
var stats = item.getStats(); | ||
// In Node 7.7.0+, binding.stat accepts a Float64Array as the second argument, | ||
// which should be filled with stat values. | ||
// In prior versions of Node, binding.stat simply returns a Stats instance. | ||
if (callback instanceof Float64Array) { | ||
fillStatsArray(stats, callback); | ||
} else { | ||
return new Stats(stats); | ||
} | ||
}); | ||
@@ -298,3 +332,4 @@ }; | ||
* @param {number} fd File descriptor. | ||
* @param {function(Error, Stats)} callback Callback (optional). | ||
* @param {function(Error, Stats)|Float64Array} callback Callback (optional). In Node 7.7.0+ this will be a Float64Array | ||
* that should be filled with stat values. | ||
* @return {Stats|undefined} Stats or undefined (if sync). | ||
@@ -306,3 +341,12 @@ */ | ||
var item = descriptor.getItem(); | ||
return new Stats(item.getStats()); | ||
var stats = item.getStats(); | ||
// In Node 7.7.0+, binding.stat accepts a Float64Array as the second argument, | ||
// which should be filled with stat values. | ||
// In prior versions of Node, binding.stat simply returns a Stats instance. | ||
if (callback instanceof Float64Array) { | ||
fillStatsArray(stats, callback); | ||
} else { | ||
return new Stats(stats); | ||
} | ||
}); | ||
@@ -942,3 +986,4 @@ }; | ||
* @param {string} filepath Path. | ||
* @param {function(Error, Stats)} callback Callback (optional). | ||
* @param {function(Error, Stats)|Float64Array} callback Callback (optional). In Node 7.7.0+ this will be a Float64Array | ||
* that should be filled with stat values. | ||
* @return {Stats|undefined} Stats or undefined (if sync). | ||
@@ -952,3 +997,12 @@ */ | ||
} | ||
return new Stats(item.getStats()); | ||
var stats = item.getStats(); | ||
// In Node 7.7.0+, binding.stat accepts a Float64Array as the second argument, | ||
// which should be filled with stat values. | ||
// In prior versions of Node, binding.stat simply returns a Stats instance. | ||
if (callback instanceof Float64Array) { | ||
fillStatsArray(stats, callback); | ||
} else { | ||
return new Stats(item.getStats()); | ||
} | ||
}); | ||
@@ -955,0 +1009,0 @@ }; |
{ | ||
"name": "mock-fs", | ||
"description": "A configurable mock file system. You know, for testing.", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/tschaub/mock-fs", |
261161
7536