os: add os.devNull #38569
os: add os.devNull #38569
Conversation
|
I'm not sure if it makes sense but it is similar to |
|
|
||
| Provides the platform-specific file path of the null device: | ||
|
|
||
| * `\\.\nul` on Windows |
RaisinTen
May 6, 2021
Member
https://docs.python.org/3/library/os.html#os.devnull says:
'/dev/null' for POSIX, 'nul' for Windows.
So, why isn't this just 'nul' for Windows?
lpinca
May 6, 2021
Author
Member
Because if you do something like
fs.writeFileSync(path.devnull, 'foo');it does not work as expected.
|
Should we add a test that attempts to write something to the file and then asserts that the file size is 0? |
|
I'm -0 on adding this, but if anything it should probably live on |
|
Dropping this off |
|
@mscdex I thought about that but the same argument can be done for I don't like to have it on both |
|
@jasnell tests, I used it here https://github.com/lpinca/fritzbox-checksum/blob/fe8311da86062a3c748b9bc3e69abdb28bb9003b/test/test.js#L83. It could definitely be done differently but why if a null device exists? |
|
Hmmm.. ok. Thinking about it further, hanging it off |
|
+1 to a method in os, even if the implementations just return a static string. |
|
@devsnek I'm fine with moving it to |
Those are components of a path, so to me it makes sense for them to live on |
|
Fair enough, moved it to |
This comment has been hidden.
This comment has been hidden.
|
I think it should be |
I agree. I'm ok with the method and the current naming and definitely wouldn't block it (which is why I signed off) but my preference would be a simple property. |
|
There is
I'm just trying to make things consistent. |
I always have considered this to be a silly mistake. It never should have been a function and I'd rather not repeat that mistake here. If there's a need to consult the operating system or libuv for the value, that's one thing, but this is just a string constant. I'm -1 on it being a function |
The same silly mistake was also done for |
|
I've force pushed to move it to |
Provides the platform-specific file path of the null device.
|
@Trott @jasnell @RaisinTen @cjihrig is this in its current form acceptable? The check can easily be done in userland so I'm fine with closing if it is controversial. |
This comment has been hidden.
This comment has been hidden.
|
Still LGTM! |
|
LGTM |
|
LGTM |
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
| const devNull = os.devNull; | ||
| if (common.isWindows) { | ||
| assert.strictEqual(devNull, '\\\\.\\nul'); | ||
| } else { | ||
| assert.strictEqual(devNull, '/dev/null'); | ||
| } |
bl-ue
May 29, 2021
•
Contributor
Any reason not to store os.devNull in a separate variable? I'm not getting it.
| const devNull = os.devNull; | |
| if (common.isWindows) { | |
| assert.strictEqual(devNull, '\\\\.\\nul'); | |
| } else { | |
| assert.strictEqual(devNull, '/dev/null'); | |
| } | |
| if (common.isWindows) { | |
| assert.strictEqual(os.devNull, '\\\\.\\nul'); | |
| } else { | |
| assert.strictEqual(os.devNull, '/dev/null'); | |
| } |
|
Landed in 152d675 |
Provides the platform-specific file path of the null device. PR-URL: #38569 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Provides the platform-specific file path of the null device. PR-URL: #38569 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Provides the platform-specific file path of the null device. PR-URL: #38569 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Provides the platform-specific file path of the null device. PR-URL: #38569 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>


Provides the platform-specific file path of the null device.