TheSpyder / rescript-nodejs

Node bindings for ReScript
MIT License
80 stars 16 forks source link

types of Fs.stat and Fs.lstat different #13

Closed AisonSu closed 1 year ago

AisonSu commented 1 year ago

According to Nodejs Document: lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the file that it refers to ,The signatures should be same, But actually it is string => Js.Promise.t<Stats.t> = "lstat" for lstat and FileHandle.t => Js.Promise.t<Stats.t> = "stat" for stat

TheSpyder commented 1 year ago

This took me a while to track down. I'm guessing you're browsing the code, not just relying on IDE autocomplete, because There is no Fs.stat() binding. What we have is Fs.Filehandle.stat(): https://nodejs.org/api/fs.html#filehandlestatoptions https://github.com/TheSpyder/rescript-nodejs/blob/f20b20744cf66440b4f4cc2983838ebaff8995bd/src/Fs.res#L267-L297

The Fs.lstat() binding is as you say, with an additional variant for the bigint return: https://nodejs.org/api/fs.html#fspromiseslstatpath-options https://github.com/TheSpyder/rescript-nodejs/blob/f20b20744cf66440b4f4cc2983838ebaff8995bd/src/Fs.res#L374-L378

I can only speculate about why the original maintainers wrote it this way, it's been there since the first commit. If you think it is necessary to have both Fs.lstat() and Fs.atat() feel free to submit a PR :)