graceful-fs
Advanced tools
Comparing version 1.1.1 to 1.1.2
// this keeps a queue of opened file descriptors, and will make | ||
// fs operations wait until some have closed before trying to open more. | ||
var fs = require("fs") | ||
, FastList = require("fast-list") | ||
// there is such a thing as TOO graceful. | ||
if (fs.open === gracefulOpen) return | ||
var FastList = require("fast-list") | ||
, queue = new FastList() | ||
@@ -9,11 +14,13 @@ , curOpen = 0 | ||
exports = module.exports = fs | ||
fs.MIN_MAX_OPEN = 64 | ||
fs.MAX_OPEN = 1024 | ||
fs._open = fs.open | ||
fs._openSync = fs.openSync | ||
fs._close = fs.close | ||
fs._closeSync = fs.closeSync | ||
var originalOpen = fs.open | ||
, originalOpenSync = fs.openSync | ||
, originalClose = fs.close | ||
, originalCloseSync = fs.closeSync | ||
@@ -31,3 +38,5 @@ | ||
fs.open = function (path, flags, mode, cb) { | ||
fs.open = gracefulOpen | ||
function gracefulOpen (path, flags, mode, cb) { | ||
if (typeof mode === "function") cb = mode, mode = null | ||
@@ -56,3 +65,3 @@ if (typeof cb !== "function") cb = noop | ||
curOpen ++ | ||
fs._open(path, flags, mode, function (er, fd) { | ||
originalOpen.call(fs, path, flags, mode, function (er, fd) { | ||
if (er) { | ||
@@ -68,3 +77,3 @@ onclose() | ||
curOpen ++ | ||
return fs._openSync(path, flags, mode) | ||
return originalOpenSync.call(fs, path, flags, mode) | ||
} | ||
@@ -88,3 +97,3 @@ | ||
cb = cb || noop | ||
fs._close(fd, function (er) { | ||
originalClose.call(fs, fd, function (er) { | ||
onclose() | ||
@@ -97,3 +106,3 @@ cb(er) | ||
onclose() | ||
return fs._closeSync(fd) | ||
return originalCloseSync.call(fs, fd) | ||
} | ||
@@ -100,0 +109,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "fs monkey-patching to avoid EMFILE and other problems", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6790
176