Code Monkey home page Code Monkey logo

node-graceful-fs's Introduction

graceful-fs

graceful-fs functions as a drop-in replacement for the fs module, making various improvements.

The improvements are meant to normalize behavior across different platforms and environments, and to make filesystem access more resilient to errors.

Improvements over fs module

  • Queues up open and readdir calls, and retries them once something closes if there is an EMFILE error from too many file descriptors.
  • fixes lchmod for Node versions prior to 0.6.2.
  • implements fs.lutimes if possible. Otherwise it becomes a noop.
  • ignores EINVAL and EPERM errors in chown, fchown or lchown if the user isn't root.
  • makes lchmod and lchown become noops, if not available.
  • retries reading a file if read results in EAGAIN error.

On Windows, it retries renaming a file for up to one second if EACCESS or EPERM error occurs, likely because antivirus software has locked the directory.

USAGE

// use just like fs
var fs = require('graceful-fs')

// now go and do stuff with it...
fs.readFile('some-file-or-whatever', (err, data) => {
  // Do stuff here.
})

Sync methods

This module cannot intercept or handle EMFILE or ENFILE errors from sync methods. If you use sync methods which open file descriptors then you are responsible for dealing with any errors.

This is a known limitation, not a bug.

Global Patching

If you want to patch the global fs module (or any other fs-like module) you can do this:

// Make sure to read the caveat below.
var realFs = require('fs')
var gracefulFs = require('graceful-fs')
gracefulFs.gracefulify(realFs)

This should only ever be done at the top-level application layer, in order to delay on EMFILE errors from any fs-using dependencies. You should not do this in a library, because it can cause unexpected delays in other parts of the program.

Changes

This module is fairly stable at this point, and used by a lot of things. That being said, because it implements a subtle behavior change in a core part of the node API, even modest changes can be extremely breaking, and the versioning is thus biased towards bumping the major when in doubt.

The main change between major versions has been switching between providing a fully-patched fs module vs monkey-patching the node core builtin, and the approach by which a non-monkey-patched fs was created.

The goal is to trade EMFILE errors for slower fs operations. So, if you try to open a zillion files, rather than crashing, open operations will be queued up and wait for something else to close.

There are advantages to each approach. Monkey-patching the fs means that no EMFILE errors can possibly occur anywhere in your application, because everything is using the same core fs module, which is patched. However, it can also obviously cause undesirable side-effects, especially if the module is loaded multiple times.

Implementing a separate-but-identical patched fs module is more surgical (and doesn't run the risk of patching multiple times), but also imposes the challenge of keeping in sync with the core module.

The current approach loads the fs module, and then creates a lookalike object that has all the same methods, except a few that are patched. It is safe to use in all versions of Node from 0.8 through 7.0.

v4

  • Do not monkey-patch the fs module. This module may now be used as a drop-in dep, and users can opt into monkey-patching the fs builtin if their app requires it.

v3

  • Monkey-patch fs, because the eval approach no longer works on recent node.
  • fixed possible type-error throw if rename fails on windows
  • verify that we never get EMFILE errors
  • Ignore ENOSYS from chmod/chown
  • clarify that graceful-fs must be used as a drop-in

v2.1.0

  • Use eval rather than monkey-patching fs.
  • readdir: Always sort the results
  • win32: requeue a file if error has an OK status

v2.0

  • A return to monkey patching
  • wrap process.cwd

v1.1

  • wrap readFile
  • Wrap fs.writeFile.
  • readdir protection
  • Don't clobber the fs builtin
  • Handle fs.read EAGAIN errors by trying again
  • Expose the curOpen counter
  • No-op lchown/lchmod if not implemented
  • fs.rename patch only for win32
  • Patch fs.rename to handle AV software on Windows
  • Close #4 Chown should not fail on einval or eperm if non-root
  • Fix npm/fstream#1 Only wrap fs one time
  • Fix #3 Start at 1024 max files, then back off on EMFILE
  • lutimes that doens't blow up on Linux
  • A full on-rewrite using a queue instead of just swallowing the EMFILE error
  • Wrap Read/Write streams as well

1.0

  • Update engines for node 0.6
  • Be lstat-graceful on Windows
  • first

node-graceful-fs's People

Contributors

addaleax avatar alloy-d avatar bluelovers avatar chalker avatar coreyfarrell avatar davidaurelio avatar dylang avatar etiktin avatar feelychau avatar heavyk avatar isaacs avatar leedm777 avatar malud avatar mbargiel avatar mischnic avatar myrne avatar nlf avatar ramosbugs avatar reid avatar romainmuller avatar ryan-allen avatar sam-github avatar simenb avatar tamird avatar thefourtheye avatar welwood08 avatar yamadapc avatar yoshixi avatar zaubernerd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-graceful-fs's Issues

cannot install version 4

Whatever I do, I end up with version 3.3.12!

This is my package:
package.zip
and I'm running 'npm install' from the folder containing this package.
When running 'npn -v graceful-fs' I'm getting 3.3.12

Please help: what am I doing wrong?

Uncaught TypeError: Cannot read property 'prototype' of undefined

So, I have looked into this issue as much as I possibly can, and I cannot trace the source of this issue to anywhere, but here. When I run my app in Google Chrome (version 51.0.2704.106) and Microsoft Edge (version 38.14372.0.0), I get an error on the console that stops all script execution:

Uncaught TypeError: Cannot read property 'prototype' of undefined

The issue seems to be thrown on line 157 of the script...I am not too sure what is causing it...

I have tried Node version 6.3.0 and version 4.4.7, both using the 64-bit version. I have completely deleted my node_modules and installed them from scratch, and the error still persists. The worst part is that it was working previously, then stopped.

silent failure when attempting to write too many files

@fresheneesz reported this bug at nodejs/node-v0.x-archive#8399

He has the following test program:

var stream = require('stream')
var fs = require("graceful-fs")

for(var x=0; x<10000; x++) {
    var filename = __dirname+'/x/'+x
    var s = new stream.PassThrough()
    s.write("moo"+x)
    fs.createWriteStream(filename, s)
}

This program writes files in the x directory up until 1014, after which the program simply exits with no error at all, but there is no file created for 1015 and above. He's on node v0.10.25, centos 6.5.

readFile doesn't call callback -- OSX 10.9.2

Using graceful-fs 2.0.3, I'm running OSX 10.9.2, Node 0.10.26. This code never results in a callback:

  fs.readFile(file.path, function (err, data) {
    if (data) {
      file.contents = data;
    }
    cb(err, file);
  });

This code works fine:

  var data = fs.readFileSync(file.path);
  var err = null;
  if (data) {
    file.contents = data;
  }
  cb(err, file);

Am I losing my mind?

please tell module authors not to use this in the README

This module is awesome. I don't know why it's not just in core node.js all the time.

I often want to require it in my applications. However sometimes I don't want to require it, but I end up requiring it anyway, because 8 module dependencies down the chain, some module has depended on graceful-fs without understanding the consequences.

Can we put a notice in the README that says, "HEY MODULE AUTHORS do not depend on this. This is for applications to depend on only."

For example: EvanOxfeld/node-unzip#54

Can't install graceful-fs

luog@luog-Satellite-P50-A:~/p/xprj/xprj⟫ npm install graceful-fs
npm WARN install Couldn't install optional dependency: Unsupported

my nodejs and npm version:

luog@luog-Satellite-P50-A:~/p/xprj/xprj⟫ nodejs -v
v5.4.1
luog@luog-Satellite-P50-A:~/p/xprj/xprj⟫ npm -v
3.3.12

OS X Mavericks, cannot find module graceful-fs

I tried removing and re-installing node many times to get graceful-fs module to work but no luck. The graceful-fs direcotry exists under:
usr/local/lib/node_modules/

Still when I run my NodeJS app, it cannot find the module.

Thank you!

graceful-fs does not work properly with io.js

When using fs functions like readFile(), graceful-fs is not in the loop when running with io.js. To reproduce:

var gfs = require("graceful-fs");

gfs.readFile('package.json', function(err, res) {
    console.log(res.toString());
 });

and the package.json:

{
    "name": "name",
    "description": "description",
    "author": "author",
    "version": "1.0.0",
    "main": "pathToMain",
    "dependencies": {
        "graceful-fs": "*"
    }
}

I added a console.log() statement into graceful-fs to make sure its hit:

Req.prototype.done = function (er, result) {
  console.log("DONE: ", er, result);

When running with node.js, the output shows up, but not with io.js.

According to electron/electron#1903 (comment) this is caused by io.js now calling binding.open() and no longer fs.open() for readFile.

eventually EMFILE error is thrown...

using graceful-js to serve videos via http, using createReadStream
eventually throws errors:

events.js:72
throw er; // Unhandled 'error' event
^
Error: accept EMFILE
at errnoException (net.js:901:11)
at TCP.onconnection (net.js:1159:24)

graceful allows the application to run a bit more, without it i get the error:
error on readstream:Error: EMFILE, open 'video.mp4'
after a few benchmarks:
ab -c 200 -n 200 http://127.0.0.1:8080/video.mp4

using node 10.0.15 (on centos linux)
here is the complete code (the http request handler is in the function
serveStream.

the error originates in the core modules as i mentioned above, simple replace
graceful with the original require('fs') and the error pops our very soon (after 2-3 ab tests)

var http = require('http');
var fs = require('graceful-fs');
//var fs = require('fs');
var util = require('util');
var version = "0.56";
var mediaPath = 'G:/movies';
mediaPath = '/media_iphone';

cache = {
    fileStat:{} 
}


function log(str,data){
    //console.log.apply(this,arguments);
    console.log("log:"+str);

}

function logError(str,data){
    //console.log.apply(this,arguments);
    console.log("error:"+str);

}

function logWarn(str,data){
    //console.log.apply(this,arguments);
    console.log("warn:"+str);
}



function contentTypeSelector(ctype){
    if (!contentTypes[ctype]) return contentTypes["default"];
    return contentTypes[ctype];
}


// todo: do authentication here
function checkHeadersAuth(req){
    var h = req.headers;

    if (req.url.indexOf("favicon")>-1) return false;
    return true;
    if (h["user-agent"].indexOf("Mozilla")==-1) { // invalid headers
        return true;
    }
    return true;
}

/*
returns a metadata object for logging each request)
*/
function collectRequestMeta(req){
    var o = req.headers;
    o.url = req.url;
    o.ip = req.connection.remoteAddress;
    return o;
}

function responseError404(res) {
    res.writeHead(404,{'content-type':contentTypeSelector('html')});
    res.end();
}


function response200(res,str){
    res.writeHead(200,{'content-type':contentTypeSelector('html')});
    res.end(str || "");
}



var contentTypes = {
    "default":"text/html",
    "video":"video/mp4",
    "text":"text/json",
    "html":"text/html"
}


var server = require('http').createServer(function (req,res){

    var filename,readStream;

    log("Got Request from url:"+req.url);

    //readStream.setEncoding('utf-8');
    if (!checkHeadersAuth(req)) {
        log("not authorized, exiting, ip:"+req.connection.remoteAddress);
        responseError404(res);
        return;
    }

    filename = mediaPath+req.url

    log("accessing filename:"+filename)
    if (!cache.fileStat[filename])  { // caching the file stat for later use
        log("loading file");
        fs.stat(filename,function(err,stat){
            if (err) {
                responseError404(res);
                err('File Not Found',{request:collectRequestMeta(req),filename:filename});
                return;
            } 
            cache.fileStat[filename] = stat;
            serveStream(req,res,cache.fileStat[filename],filename);         
        });
        return;
    } 
    log("getting file from cache");
    serveStream(req,res,cache.fileStat[filename],filename);

});

/*
serves the stream when we have the proper file 
and have not failed
*/
function serveStream(req,res,stat,filename) {
    log("serverStream()")
    var total = stat.size;
    var file,responseType;
    var header = {};
    if (req.headers['range']) {
        var range = req.headers.range;
        var parts = range.replace(/bytes=/, "").split("-");
        var partialstart = parts[0];
        var partialend = parts[1];

        var start = parseInt(partialstart, 10);
        var end = partialend ? parseInt(partialend, 10) : total-1;
        var chunksize = (end-start)+1;
        console.log('RANGE: ' + start + ' - ' + end + ' = ' + chunksize);
        file = fs.createReadStream(filename, {start: start, end: end,autoClose:false});
        header = { 'Content-Range': 'bytes ' + start + '-' + end + '/' + total, 'Accept-Ranges': 'bytes', 'Content-Length': chunksize, 'Content-Type': contentTypeSelector('video')};
        responseType = 206;
    } else {
        responseType = 200;     
        file = fs.createReadStream(filename,{autoClose:false,bufferSize:16*1024});
        header = { 'Content-Length': total, 'Content-Type': contentTypeSelector('video')};
    }


    file.on('open',function(fd){
        //log("opening stream:"+fd);
        res.writeHead(responseType, header);
        ///file.pipe(res);  
    })
    file.on('close',function(){
        //log("closing stream");
        file.destroy();
        res.end();
    });
    file.on('end',function(){
        //log("ending stream");
        file.destroy();
    });
    file.on('error',function(msg){
        logError('error on readstream:'+msg);
    });

    file.pipe(res);

}

server.listen(8080);
//log('server started, scope:'+this,__filename+' version:'+version);    
log('server started, version:'+version);    


change "mediaPath" to your directory containing the video to serve
and run the ab test 4-5 times (stop each test after a few seconds (10-30) as it will try to get the whole video for it to end)

I'm serving videos sizes of 100-3000 mbs.

opened an issue (which was closed) at:
nodejs/node-v0.x-archive#6041

error with: sudo npm install graceful-fs

@archlinux ➜  ~  ᐅ  sudo npm install graceful-fs


npm ERR! Linux 4.7.0-1-zen
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "graceful-fs"
npm ERR! node v6.4.0
npm ERR! npm  v3.10.6
npm ERR! file /home/edward/package.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! No data, empty input at 1:1
npm ERR! 
npm ERR! ^
npm ERR! File: /home/edward/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! Please include the following file with any support request:
npm ERR!     /home/edward/npm-debug.log

npm-debug.log here

Please help me out with this issue, I need graceful-fs installed for atom editor

3.0.3 regression on Node 0.10

It looks like 34e473a (from #31) introduced an issue with Node 0.10.

Here is a script that reproduces the issue:

var fs = require('graceful-fs');

// first make some files
fs.mkdirSync('files');
var num = 333;
var paths = new Array(num);

for (var i = 0; i < num; ++i) {
  paths[i] = 'files/file-' + i;
  fs.writeFileSync(paths[i], 'content');
}

// now read them
var done = 0;
for (var i = 0; i < num; ++i) {
  fs.readFile(paths[i], function(err, data) {
    if (err) {
      console.error(err);
      process.exit(1);
    }
    ++done;
    if (done == num) {
      console.log('success');
    }
  });
}

With [email protected], this works on Node 0.11.13 and fails on 0.10.28.

$ rm -rf files/ && node test.js 
(libuv) Failed to create kqueue (24)
(libuv) Failed to create kqueue (24)

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: write EBADF
    at errnoException (net.js:904:11)
    at WriteStream.Socket._write (net.js:645:26)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at WriteStream.Writable.write (_stream_writable.js:183:11)
    at WriteStream.Socket.write (net.js:615:40)
    at Console.warn (console.js:61:16)
    at /Users/tschaub/projects/emfile/test.js:18:15
    at fs.js:207:20
    at Object.oncomplete (fs.js:107:15)

With [email protected] (eval evil notwithstanding) this works on Node 0.11 and 0.10.

Bump to v4.1.9 broke our test suite

After upgrading to 4.1.9, our mocha tests fail and gives the following output:

/home/ubuntu/wrench/node_modules/bluebird/js/release/debuggability.js:673
    var firstStackLines = firstLineError.stack.split("\n");
                                        ^
NetworkError: 
npm ERR! Test failed.  See above for more details.

npm test returned exit code 1

npm WARN deprecated version!

npm WARN deprecated [email protected]: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.


But after command prompt npm install -g graceful-fs@^4.0.0

npm ERR! No compatible version found: [email protected] npm ERR! Valid
install targets: npm ERR! 4.1.3, 4.1.2, 4.1.1, 4.1.0, 3.0.8, 3.0.7,
3.0.6, 3.0.5, 3.0.4, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 1.2.3, 1.2.2, 1.2.1, 1.2.0, 1.1.14, 1.1.13, 1.1.12, 1.1.11, 1.1.10, 1.1.9, 1.1.8, 1.1.7, 1.1.6, 1.1.5, 1.1.4, 1.1.3, 1.1.2, 1.1.1, 1.1.0, 1.0.2, 1.0.1, 1.0.0


Updated with latest 4.1.3 version, but the warn message still...

use of graceful-fs causes fs.stat object to not be an instance of fs.Stats on 0.11.13

nodejs/node-v0.x-archive#7203 introduced a change where fs.Stats is defined in lib/fs.js, and passed to the binding with FSInitialize().

graceful-fs reevaluates the fs source code, causing a new instantiation of a source-identical fs.Stats function to be passed to FSInitialize.

After requireing graceful-fs, the stat object returned by fs.stat and friends will no longer be an instance of require('fs').Stats, but it will be an instance of require('graceful-fs').Stats.

This breaks the node API contract (http://nodejs.org/api/fs.html#fs_class_fs_stats) and causes chaos, generally, see expressjs/express#2351

As far as I can tell, the nastiness of https://github.com/isaacs/node-graceful-fs/blob/master/fs.js is unnecessary.

Why not replace fs.js with module.exports = util._extend({}, require('fs')) ?

Reproduction:

var fs = require('fs');
var g = require('graceful-fs');

var stat = fs.statSync(__filename);
console.log('is fs.Stats?', stat instanceof fs.Stats);
console.log('is g.Stats?', stat instanceof g.Stats);

[bug] cannot run in strict mode

hello isaacs

just tried to run my app in strict mode and found this error in the console:

.../node_modules/fs-extra/node_modules/rimraf/node_modules/graceful-fs/graceful-fs.js:86
    open(req.path, req.flags || "r", req.mode || 0777, req.cb)
                                                 ^^^^
SyntaxError: Octal literals are not allowed in strict mode.

just type 511 (decimal) instead of 0777 (octal) and you'll be golden. thanks.

EINVAL should not be a fatal error when chown-ing

Per https://github.com/isaacs/npm/issues/1570

The problem is that some files cannot be chowned, even if you're root. The pertinent example here would be a squashed NFS mount - try as you will, you can't change the owner.

This will result in EINVAL. Here's me attempting to chown a squashed NFS-mounted file:

fchownat(AT_FDCWD, "resources.dot", 1000, 1000, 0) = -1 EINVAL (Invalid argument)

Here's the source for cp dealing with the same:

      if (x->preserve_ownership)
        {
          if (lchown (dst_name, p->st.st_uid, p->st.st_gid) != 0)
            {
              if (! chown_failure_ok (x))
                {
                  error (0, errno, _("failed to preserve ownership for %s"),
                         quote (dst_name));
                  return false;
                }
              /* Failing to preserve ownership is OK. Still, try to preserve
                 the group, but ignore the possible error. */
              ignore_value (lchown (dst_name, -1, p->st.st_gid));
            }
        }

Specifically:

chown_failure_ok (struct cp_options const *x)
{
  /* If non-root uses -p, it's ok if we can't preserve ownership.
     But root probably wants to know, e.g. if NFS disallows it,
     or if the target system doesn't support file ownership.  */

  return ((errno == EPERM || errno == EINVAL) && !x->chown_privileges);
}

Steps to reproduce: export a directory with at least these options: all_squash,anonuid=1000,anongid=1000

Mount the directory and attempt to install a package into that directory.

Help Needed

Hello when ever i tried to install the other dependecies needed for production i got the following errors
npm WARN install Couldn't install optional dependency: Unsupported
npm ERR! Windows_NT 10.0.10240
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Users\lepat\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "install"
npm ERR! node v5.1.0
npm ERR! npm v3.3.12
npm ERR! file C:\Users\lepat\AppData\Roaming\npm-cache\graceful-fs\4.1.2\package\package.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! Unexpected token '\u0000' at 1:1
npm ERR!
npm ERR! ^
npm ERR! File: C:\Users\lepat\AppData\Roaming\npm-cache\graceful-fs\4.1.2\package\package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! Please include the following file with any support request:
npm ERR! C:\wamp\www\p1\npm-debug.log

thanks for the help

fs.lstatSync() isn't instance of fs.Stats on Node.js 0.12

Result of fs.lstatSync() isn't instance of fs.Stats with [email protected] on Node.js 0.11. This problem doesn't occur with [email protected].

Example code (index.js) as follows.

var gfs = require("graceful-fs");
var fs = require("fs");
var path = "file1.txt";

gfs.writeFileSync(path, "Files Test");
console.log(gfs.lstatSync(path) instanceof fs.Stats);
gfs.unlinkSync("file1.txt");

[email protected]:

$ node -v
v0.11.14
$ node index.js
true

[email protected]:

$ node -v
v0.11.14
$ node index.js
false

graceful-fs exposes the original `fs.close` method, thus skipping retry when using `.open()`/`.close()`

graceful-fs exposes the original fs.close method as close, rather than a patched version.

When using lower-level methods than readFile, like open/read/close, graceful-fs will never retry scheduled operations, because the patched version is never invoked.

Minimal test case:

var assert = require('assert');
var fs = require('fs');
var close = fs.close; // original close
var gracefulFs = require('graceful-fs');

assert.notEqual(close, gracefulFs.close, 'graceful-fs exposes an unpatched `close` method'); // throws

The problem is that module.exports is created with a clone of fs before patching close, thus ending up with the unpatched method.

Upgrading from v3 to v4

Hi, could you explain the breaking changes (if any) that I may incur by upgrading this package from v3.x to v4.x?

Find the EMFILE limit

Rather than having MAX_FILES start at 256, instead start at 1024. Then, when/if EMFILE occurs, set the new limit at that value, and put the failing open call into the queue.

Windows 8 error code is not EMFILE (is OK)

Hiya,

I found this library while having too many open file errors on Windows 8, except on Windows 8 the error code was coming back as OK.

I added this to Req.prototype.done's if statement to check for EMFILE or OK and all worked fine.

I'm not sure if this is just a Windows 8 thing or anything, but yeah!

Release 4.1.7 causes TypeError: Cannot read property 'uid' of undefined

Started getting this error right now and noticed that the only difference in my builds was the new version of graceful-fs 4.1.7, which was released 20 min ago...

> cross-env NODE_ENV=production webpack --display-chunks --progress
C:\a\1\s\Source\PoeStats\node_modules\graceful-fs\polyfills.js:264
      if (stats.uid < 0) stats.uid += 0x100000000
               ^
TypeError: Cannot read property 'uid' of undefined
    at C:\a\1\s\Source\PoeStats\node_modules\graceful-fs\polyfills.js:264:16
    at FSReqWrap.oncomplete (fs.js:82:15)

Handle EMFILE in writeFile calls

I'm on Ubuntu (64bit machine, ulimit -n === 1024) and I get an EMFILE when trying to write too many files in a short period of time.
It'd be nice if graceful-fs had for writes the same behavior it has for reads (try later if EMFILE).

npm WARN deprecated message a bit unclear

npm WARN deprecated [email protected]: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.

Hi @isaacs, does it feel like this message could be improved by specifying which 'newer node releases' will be broken? Is it broken for node 4 LTS or 5 or both?

Thanks

support node v6.0

when I compiled using debowerify,I get follow message.

(node:6292) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.

fortunately,I using nvm,so I switched simply,but supporting wide range is important.

Weird issue with tap

test/open.js does require("tap"), yet installing tap locally results in a weird error.
But if you don't install tap locally, require won't work.
The work-around that I found is to do npm link tap to use the global install.
Maybe this could be put in the readme?

Mac-Mini:node-graceful-fs meryn$ npm install tap
[email protected] node_modules/tap
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected])
Mac-Mini:node-graceful-fs meryn$ npm test

> [email protected] test /Users/meryn/Code/node-graceful-fs
> tap test/*.js


module.js:340
    throw err;
          ^
Error: Cannot find module 'graceful-fs'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/meryn/Code/node-graceful-fs/node_modules/tap/node_modules/glob/glob.js:39:10)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0
Mac-Mini:node-graceful-fs meryn$ rm -rf node_modules/
Mac-Mini:node-graceful-fs meryn$ npm link tap
/Users/meryn/Code/node-graceful-fs/node_modules/tap -> /usr/local/lib/node_modules/tap
Mac-Mini:node-graceful-fs meryn$ npm test

> [email protected] test /Users/meryn/Code/node-graceful-fs
> tap test/*.js

ok test/open.js ....................................... 14/14
total ................................................. 14/14

ok
Mac-Mini:node-graceful-fs meryn$

Deprecate all versions prior to 4.x

Users should be warned that their setups will we soon broken with new Node.js releases.

This means to push a patch release to 1.x, 2.x, and 3.x branches.
Something similar to what lodash does:

npm WARN deprecated [email protected]: lodash@<3.0.0 is no longer maintained. Upgrade to lodash@^4.0.0.
npm WARN deprecated [email protected]: lodash@<3.0.0 is no longer maintained. Upgrade to lodash@^4.0.0.

Tracking issue: nodejs/node#5213

Push bugfix into new version

I ran into an issue with one of my projects and in debugging it I found out it was caused by this library (as a dependency of glob).
Upon further inspection, I found it was already fixed a recent commit, but you haven't propagated it as a hotfix-release.
Could you please do this and also update your glob-package so that it uses the fixed release?

Please clarify licensing

The repository contains MIT license text, but package.json says '"license": "BSD"'. Could someone please clarify whether project is under MIT or BSD?

Thanks

Bad argument TypeError (using fs.createWriteStream)

When I use a file write-stream in one of my modules and graceful-fs is loaded somewhere else it breaks the writing to that filestream with:

fs.js:307
  binding.write(fd, buffer, offset, length, position, wrapper);
          ^
TypeError: Bad argument
    at [object Object].<anonymous> (fs.js:307:11)
    at [object Object].flush (fs.js:1312:10)
    at Object.oncomplete (fs.js:1304:10)

Here a simplified example how you can reproduce this error (using node version 0.6.14).

var fs = require('fs');
var stream = fs.createWriteStream('foo.txt');
// could be loaded in another module (e.g. rimraf)
require('graceful-fs');
stream.write('foo');

I've stumpled upon this issue after doing npm install with a newer npm version (Version 1.1.5) on a project where rimraf is used.

With version 1.1.15 of npm it somehow installed the optionalDependencies (https://github.com/isaacs/rimraf/blob/master/package.json#L8) of rimraf and I didn't found any reference how to avoid the installation of this optional dependency. Maybe this should be reported to the npm project directly?

question about implementation details

Hi, I like graceful-fs an am thinking to use it in http://npmjs.com/package/fildes I have a couple of questions and hope it is ok to ask here.

Retrying the queue, happens on some of the 'shimed' methods like close, closeSync. Does that work in multiple child processes that each try to write many files, as I suppose if one child process gets too many file descriptors error and the other process then calls close, the first isn't informed that something happend?

What does the polyfills.js and legacy-streams.js do? and what impact has it if I only want to use Node.js 4.x

what is require('constants'), seems to be something Node.js internal is that correct? Is there any documentation on it somewhere?

Thanks and I hope you don't mind me asking here.

Create changelog

Or at least changelog of major bumps (what are the braking changes)?

Failed to use strict mode with NodeJS

> node --use-strict --harmony_modules --harmony_proxies --harmony_arrow_functions --harmony --es_staging lib/cli.js

...\node_modules\graceful-fs\graceful-fs.js:80
        open(req.path, req.flags || "r", req.mode || 0777, req.cb)
                                                     ^^^^

SyntaxError: Octal literals are not allowed in strict mode.
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (...\glob.js:39:10)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
npm ERR! Test failed.  See above for more details.

I found a solution, replace 0777 to 777 in graceful-fs.js:80 file.

"(libuv) Failed to create kqueue (24)" with fs.ReadFile() on 20,000+ files

I'm sure this sounds ridiculous, but I'm opening, parsing, and closing 20,000 files asynchronously and having issues when my main() loop is slow. In the example below, I'm writing each of the files to MongoDB.

var fs = require('graceful-fs'); // Queues fs.readFile()
var dive = require('dive');      // Recursive dir walking
var databaseUrl = "127.0.0.1:3002/meteor";
var collections = ["Erowid"];
var db = require("mongojs").connect(databaseUrl, collections);

var main = function(e) {
    db.Erowid.insert(e);
}

dive(__dirname + '/json', { all: false }, function (err, file) {
    fs.readFile(file, function (err, contents) {
        if (err) throw err;
        var value = main(JSON.parse(contents));
        if (typeof value === 'object') {
            fs.writeFile(file, JSON.stringify(value, null, 1) + "\r\n", function(err) {
                if (err) throw err;
            });
        }
    })
});

Should I be doing this differently, or is the kqueue error a bug? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.