Skip to content

Commit

Permalink
Fix stat calls to work with changes in Node 10
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Jul 20, 2018
1 parent 5b165be commit 0aa9a77
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions lib/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ function fillStatsArray(stats, statValues) {
* that should be filled with stat values.
* @return {Stats|undefined} Stats or undefined (if sync).
*/
Binding.prototype.stat = function(filepath, callback) {
Binding.prototype.stat = function(filepath, options, callback) {
if (arguments.length < 3) {
callback = options;
options = {};
}
return maybeCallback(wrapStatsCallback(callback), this, function() {
var item = this._system.getItem(filepath);
if (item instanceof SymbolicLink) {
Expand All @@ -345,7 +349,8 @@ Binding.prototype.stat = function(filepath, callback) {
// 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) {
if (callback instanceof Float64Array ||
callback instanceof BigUint64Array) {
fillStatsArray(stats, callback);
} else {
fillStatsArray(stats, statValues);
Expand All @@ -361,7 +366,11 @@ Binding.prototype.stat = function(filepath, callback) {
* that should be filled with stat values.
* @return {Stats|undefined} Stats or undefined (if sync).
*/
Binding.prototype.fstat = function(fd, callback) {
Binding.prototype.fstat = function(fd, options, callback) {
if (arguments.length < 3) {
callback = options;
options = {};
}
return maybeCallback(wrapStatsCallback(callback), this, function() {
var descriptor = this._getDescriptorById(fd);
var item = descriptor.getItem();
Expand All @@ -370,7 +379,8 @@ Binding.prototype.fstat = function(fd, callback) {
// 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) {
if (callback instanceof Float64Array ||
callback instanceof BigUint64Array) {
fillStatsArray(stats, callback);
} else {
fillStatsArray(stats, statValues);
Expand Down Expand Up @@ -1070,7 +1080,11 @@ Binding.prototype.readlink = function(pathname, encoding, callback) {
* that should be filled with stat values.
* @return {Stats|undefined} Stats or undefined (if sync).
*/
Binding.prototype.lstat = function(filepath, callback) {
Binding.prototype.lstat = function(filepath, options, callback) {
if (arguments.length < 3) {
callback = options;
options = {};
}
return maybeCallback(wrapStatsCallback(callback), this, function() {
var item = this._system.getItem(filepath);
if (!item) {
Expand All @@ -1081,7 +1095,8 @@ Binding.prototype.lstat = function(filepath, callback) {
// 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) {
if (callback instanceof Float64Array ||
callback instanceof BigUint64Array) {
fillStatsArray(stats, callback);
} else {
fillStatsArray(stats, statValues);
Expand Down

0 comments on commit 0aa9a77

Please sign in to comment.