Node: fs: question about chmod() mode argument type

Created on 2 May 2017  路  5Comments  路  Source: nodejs/node

  • Subsystem: fs

Doc states mode argument should be an integer. However, in the tests, this argument is sometimes intentionally cast to string. In fs lib, this function is used for string supporting.

What is going on here? :)

fs question

Most helpful comment

I think the docs are probably fine as-is since I don't think we want to start encouraging (by documenting) the use of strings since ES6 octal representation has been around for awhile now. *shrug*

All 5 comments

Octal string (e.g. '755') support was added back in 2011 (specifically https://github.com/nodejs/node/commit/5f2e90934e523b2fe102e3e5bae3ea76535ab8b5) as a way to avoid the need for calling parseInt() in user code because at that time octal representation (e.g. 0755) is/was not allowed in strict mode.

Nowadays this is no longer an issue since with ES6 we now have a new octal representation (e.g. 0o755) that can be used in either mode because the new octal format is no longer ambiguous.

As to why it's explicitly cast to a string, who knows. Perhaps to test the acceptance of strings?

So the doc better be left as is?

For the specific test you linked to, you can see that a string literal was originally used before a number converted to string was used.

I think the docs are probably fine as-is since I don't think we want to start encouraging (by documenting) the use of strings since ES6 octal representation has been around for awhile now. *shrug*

Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mcollina picture mcollina  路  3Comments

dfahlander picture dfahlander  路  3Comments

fanjunzhi picture fanjunzhi  路  3Comments

loretoparisi picture loretoparisi  路  3Comments

danielstaleiny picture danielstaleiny  路  3Comments