-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: add runtime deprecate for file stream open()
WriteStream.open() and ReadStream.open() are undocumented internal APIs that do not make sense to use in userland. File streams should always be opened through their corresponding factory methods (fs.createWriteStream() and fs.createReadStream()) or by passing a file descriptor in options. PR-URL: #29061 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: João Reis <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
- Loading branch information
Showing
4 changed files
with
113 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const fs = require('fs'); | ||
|
||
common.expectWarning( | ||
'DeprecationWarning', | ||
'ReadStream.prototype.open() is deprecated', 'DEP0XXX'); | ||
const s = fs.createReadStream('asd') | ||
// We don't care about errors in this test. | ||
.on('error', () => {}); | ||
s.open(); | ||
|
||
// Allow overriding open(). | ||
fs.ReadStream.prototype.open = common.mustCall(); | ||
fs.createReadStream('asd'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const fs = require('fs'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
|
||
// Run in a child process because 'out' is opened twice, blocking the tmpdir | ||
// and preventing cleanup. | ||
if (process.argv[2] !== 'child') { | ||
// Parent | ||
const assert = require('assert'); | ||
const { fork } = require('child_process'); | ||
tmpdir.refresh(); | ||
|
||
// Run test | ||
const child = fork(__filename, ['child'], { stdio: 'inherit' }); | ||
child.on('exit', common.mustCall(function(code) { | ||
assert.strictEqual(code, 0); | ||
})); | ||
|
||
return; | ||
} | ||
|
||
// Child | ||
|
||
common.expectWarning( | ||
'DeprecationWarning', | ||
'WriteStream.prototype.open() is deprecated', 'DEP0XXX'); | ||
const s = fs.createWriteStream(`${tmpdir.path}/out`); | ||
s.open(); | ||
|
||
// Allow overriding open(). | ||
fs.WriteStream.prototype.open = common.mustCall(); | ||
fs.createWriteStream('asd'); |