Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about implementation details #48

Closed
thisconnect opened this issue Oct 18, 2015 · 8 comments
Closed

question about implementation details #48

thisconnect opened this issue Oct 18, 2015 · 8 comments

Comments

@thisconnect
Copy link

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.

@thisconnect
Copy link
Author

To partly answer my own question

flags can also be a number as documented by open(2); commonly used constants are available from require('constants'). On Windows, flags are translated to their equivalent ones where applicable, e.g. O_WRONLY to FILE_GENERIC_WRITE, or O_EXCL|O_CREAT to CREATE_NEW, as accepted by CreateFileW.

https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback

@isaacs
Copy link
Owner

isaacs commented Sep 27, 2016

  1. File descriptors are per-process. So, you typically don't open a file descriptor in one process and close it in another. This can be done by sending the file descriptors via a sendmsg syscall, but that's rare. Even if you do sendmsg file descriptors between processes, the actual limits that cause EMFILE and ENFILE errors are per-process, so they'll requeue the opens in that process when the error is encountered.
  2. polyfills.js is polyfills for things that are broken in some versions of node or which don't exist on some operating systems. For example, lchmod is turned into a no-op instead of a nonexistent function. legacy-streams.js is there to fix streams in node v0.8.
  3. I don't know if there are any documentation pages for require('constants') but it's been there for a very long time.

@isaacs isaacs closed this as completed Sep 27, 2016
@addaleax
Copy link
Contributor

I don't know if there are any documentation pages for require('constants') but it's been there for a very long time.

Hope it’s okay to comment here! There is no documentation on it, and while it’s likely going to keep being around for a long time, the long-term direction in which Node is headed is replacing it by explicit constants properties of modules, e.g. fs.constants, which are available and documented now (in Node >= v6.3.0). See nodejs/node#6534 for a bit of context on that, if you’re interested.

@isaacs
Copy link
Owner

isaacs commented Sep 27, 2016

@addaleax Cool. Since it's only used for older versions (0.6 and before, I believe?) probably we can just add a guard around the require().

@addaleax
Copy link
Contributor

I think var constants = fs.constants || require('constants') would be safe to use here, if that’s what you’re suggesting?

@isaacs
Copy link
Owner

isaacs commented Sep 27, 2016

Or even just try { var constants = require('constants') } catch (e) { constants = {} } would probably work. I believe it only uses it when the version is below 0.6.5 or something hella old like that.

@addaleax
Copy link
Contributor

Hm – patchLutimes seems to use it for the lutimes polyfill, and I can’t seem to find fs.lutimes on any standard Node.js fs module?

I doubt it matters much. :D

@thisconnect
Copy link
Author

thank you both

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants