Michael,

As the person empowered to make definitive statements about the
direction of Node, here's the answer:

Wherever it makes sense (for some definition of "sense", of course),
Node's file system api follows the Posix patterns.

Stat, lstat, and fstat all return the same type of object.  Of course,
given a fd, there is no way to infer the path, and without an extra
readlink() call, there's no way to get the path from a symlink.  In
the case of stat, it's a bit silly to require us to give you the path
back, when you already have it, so it's omitted.  You could make the
argument that stat(2) *should* give you the path anyhow for
convenience, but you'd be making the argument about 40 years too late
:)  (If you have a time machine, and can go back to those days, tell
them that null-terminated strings are a terrible idea.)

For a similar reason, fs.open() does not tell you the path that you
gave it, fs.read() does not provide you the file descriptor, etc.
While it is sometimes convenient to repeat your arguments back to you,
it does add some complexity and surface to the API, and we've opted to
not do that in Node.  It simplifies things greatly to simply say "It
works like `man 2 stat` says it works" and be done with it.

As you've pointed out, it's very easy to work around.  Though you
asked me not to, here's a technique I use sometimes:

```
fs.stat(filename, onstat(filename));

function onstat(filename) { return function(er, stat) {
  // now I have the stat results, and the filename.
}}
```

Thanks for the good question :)


On Wed, Dec 12, 2012 at 8:37 AM, Nikita Pchelintsev <[email protected]> wrote:
>
>>
>> files.map(function(file){
>>   fs.stat(file,function(stats){
>>     if(stats.isFile()){
>>       fs.readFile(file, function(err, theFile){
>>          //dosomething
>>       })
>>     }
>>   })
>> })
>
>
>
>  I don't think this example is correct, the variable "file" in
> fs.readFile(file, function(err, theFile) call will refer to one instance for
> every callback on each "iteration" of map function. Most probably you will
> end up reading one file. Please correct me if I'm wrong.
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to