Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graceful-fs

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graceful-fs - npm Package Compare versions

Comparing version 4.1.0 to 4.1.1

test/readfile.js

111

graceful-fs.js

@@ -6,3 +6,23 @@ var fs = require('fs')

var util = require('util')
function noop () {}
var debug = noop
if (util.debuglog)
debug = util.debuglog('gfs4')
else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ''))
debug = function() {
var m = util.format.apply(util, arguments)
m = 'GFS4: ' + m.split(/\n/).join('\nGFS4: ')
console.error(m)
}
if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) {
process.on('exit', function() {
debug(queue)
require('assert').equal(queue.length, 0)
})
}
module.exports = patch(require('./fs.js'))

@@ -49,10 +69,13 @@ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH) {

return go(path, options, cb)
return go$readFile(path, options, cb)
function go (path, flags, mode, cb) {
return fs$readFile(path, options, function (err, fd) {
function go$readFile (path, options, cb) {
return fs$readFile(path, options, function (err) {
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
queue.push([go, [path, options, cb]])
else if (typeof cb === 'function')
cb.apply(this, arguments)
enqueue([go$readFile, [path, options, cb]])
else {
if (typeof cb === 'function')
cb.apply(this, arguments)
retry()
}
})

@@ -62,9 +85,51 @@ }

var fs$writeFile = fs.writeFile
fs.writeFile = writeFile
function writeFile (path, data, options, cb) {
if (typeof options === 'function')
cb = options, options = null
return go$writeFile(path, data, options, cb)
function go$writeFile (path, data, options, cb) {
return fs$writeFile(path, data, options, function (err) {
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
enqueue([go$writeFile, [path, data, options, cb]])
else {
if (typeof cb === 'function')
cb.apply(this, arguments)
retry()
}
})
}
}
var fs$appendFile = fs.appendFile
if (fs$appendFile)
fs.appendFile = appendFile
function appendFile (path, data, options, cb) {
if (typeof options === 'function')
cb = options, options = null
return go$appendFile(path, data, options, cb)
function go$appendFile (path, data, options, cb) {
return fs$appendFile(path, data, options, function (err) {
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
enqueue([go$appendFile, [path, data, options, cb]])
else {
if (typeof cb === 'function')
cb.apply(this, arguments)
retry()
}
})
}
}
var fs$readdir = fs.readdir
fs.readdir = readdir
function readdir (path, cb) {
return go(path, cb)
return go$readdir(path, cb)
function go () {
function go$readdir () {
return fs$readdir(path, function (err, files) {

@@ -75,5 +140,8 @@ if (files && files.sort)

if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
queue.push([go, [path, cb]])
else if (typeof cb === 'function')
cb.apply(this, arguments)
enqueue([go$readdir, [path, cb]])
else {
if (typeof cb === 'function')
cb.apply(this, arguments)
retry()
}
})

@@ -158,10 +226,13 @@ }

return go(path, flags, mode, cb)
return go$open(path, flags, mode, cb)
function go (path, flags, mode, cb) {
function go$open (path, flags, mode, cb) {
return fs$open(path, flags, mode, function (err, fd) {
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
queue.push([go, [path, flags, mode, cb]])
else if (typeof cb === 'function')
cb.apply(this, arguments)
enqueue([go$open, [path, flags, mode, cb]])
else {
if (typeof cb === 'function')
cb.apply(this, arguments)
retry()
}
})

@@ -174,7 +245,13 @@ }

function enqueue (elem) {
debug('ENQUEUE', elem[0].name, elem[1])
queue.push(elem)
}
function retry () {
var elem = queue.shift()
if (elem)
if (elem) {
debug('RETRY', elem[0].name, elem[1])
elem[0].apply(null, elem[1])
}
}

2

package.json
{
"name": "graceful-fs",
"description": "A drop-in replacement for fs, making various improvements.",
"version": "4.1.0",
"version": "4.1.1",
"repository": {

@@ -6,0 +6,0 @@ "type": "git",

@@ -16,3 +16,3 @@ var spawn = require('child_process').spawn

files.filter(function (f) {
if (fs.statSync(dir + '/' + f).isFile()) {
if (/\.js$/.test(f) && fs.statSync(dir + '/' + f).isFile()) {
tap.spawn(node, ['test/' + f])

@@ -19,0 +19,0 @@ return true

@@ -21,12 +21,8 @@ 'use strict'

var done = 0
t.plan(num)
for (var i = 0; i < num; ++i) {
paths[i] = 'files/file-' + i
var stream = fs.createWriteStream(paths[i])
stream.on('end', function () {
++done
if (done === num) {
t.pass('success')
t.end()
}
stream.on('finish', function () {
t.pass('success')
})

@@ -36,4 +32,2 @@ stream.write('content')

}
t.end()
})

@@ -43,14 +37,13 @@

// now read them
var done = 0
for (var i = 0; i < num; ++i) {
t.plan(num)
for (var i = 0; i < num; ++i) (function (i) {
var stream = fs.createReadStream(paths[i])
stream.on('data', function (data) {})
var data = ''
stream.on('data', function (c) {
data += c
})
stream.on('end', function () {
++done
if (done === num) {
t.pass('success')
t.end()
}
t.equal(data, 'content')
})
}
})(i)
})

@@ -57,0 +50,0 @@

@@ -29,13 +29,9 @@ var fs = require('../');

// now read them
var done = 0;
t.plan(num)
for (var i = 0; i < num; ++i) {
fs.readFile(paths[i], function(err, data) {
fs.readFile(paths[i], 'ascii', function(err, data) {
if (err)
throw err;
++done;
if (done === num) {
t.pass('success');
t.end()
}
t.equal(data, 'content')
});

@@ -42,0 +38,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc