Skip to content

Commit

Permalink
Allow stat functions to accept 3 arguments (target, options, cb)
Browse files Browse the repository at this point in the history
Since Node.js v10.5.0 the `fs.stat` function accepts an optional options
object: https://nodejs.org/docs/latest-v10.x/api/fs.html#fs_fs_stat_path_options_callback
This commit takes the optional options into account for the `statFix`
polyfill.

Closes: #158
  • Loading branch information
ZauberNerd committed May 14, 2019
1 parent 26456e3 commit 168bdb8
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,22 +277,35 @@ function patch (fs) {
if (!orig) return orig
// Older versions of Node erroneously returned signed integers for
// uid + gid.
return function (target, cb) {
return orig.call(fs, target, function (er, stats) {
if (!stats) return cb.apply(this, arguments)
return function (target, options, cb) {
if (typeof options === 'function') {
cb = options
options = null
}
function callback(err, stats) {
if (!stats && cb) return cb.apply(this, arguments)
if (stats.uid < 0) stats.uid += 0x100000000
if (stats.gid < 0) stats.gid += 0x100000000
if (cb) cb.apply(this, arguments)
})
}
if (options) {
return orig.call(fs, target, options, callback);
}
return orig.call(fs, target, callback);
}
}

function statFixSync (orig) {
if (!orig) return orig
// Older versions of Node erroneously returned signed integers for
// uid + gid.
return function (target) {
var stats = orig.call(fs, target)
return function (target, options) {
var stats
if (options) {
stats = orig.call(fs, target, options)
} else {
stats = orig.call(fs, target)
}
if (stats.uid < 0) stats.uid += 0x100000000
if (stats.gid < 0) stats.gid += 0x100000000
return stats;
Expand Down

0 comments on commit 168bdb8

Please sign in to comment.