fs: move fs stream open method to eol

The `open()` method on fs read and write streams has been
deprecated for many years. It's time to remove it while
still allowing the open method to be monkeypatched since
that's still apparently a thing.

PR-URL: https://github.com/nodejs/node/pull/58529
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
This commit is contained in:
James M Snell 2025-06-02 09:54:31 -07:00 committed by GitHub
parent df16f0fd8d
commit a273674dee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 38 deletions

View File

@ -2810,12 +2810,15 @@ an officially supported API.
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/58529
description: End-of-Life.
- version: v13.0.0
pr-url: https://github.com/nodejs/node/pull/29061
description: Runtime deprecation.
-->
Type: Runtime
Type: End-of-Life
[`WriteStream.open()`][] and [`ReadStream.open()`][] are undocumented internal
APIs that do not make sense to use in userland. File streams should always be

View File

@ -19,7 +19,6 @@ const {
ERR_SYSTEM_ERROR,
} = require('internal/errors').codes;
const {
deprecate,
kEmptyObject,
} = require('internal/util');
const {
@ -52,7 +51,7 @@ function _construct(callback) {
return;
}
if (stream.open !== openWriteFs && stream.open !== openReadFs) {
if (typeof stream.open === 'function') {
// Backwards compat for monkey patching open().
const orgEmit = stream.emit;
stream.emit = function(...args) {
@ -238,11 +237,6 @@ ObjectDefineProperty(ReadStream.prototype, 'autoClose', {
},
});
const openReadFs = deprecate(function() {
// Noop.
}, 'ReadStream.prototype.open() is deprecated', 'DEP0135');
ReadStream.prototype.open = openReadFs;
ReadStream.prototype._construct = _construct;
ReadStream.prototype._read = function(n) {
@ -407,11 +401,6 @@ ObjectDefineProperty(WriteStream.prototype, 'autoClose', {
},
});
const openWriteFs = deprecate(function() {
// Noop.
}, 'WriteStream.prototype.open() is deprecated', 'DEP0135');
WriteStream.prototype.open = openWriteFs;
WriteStream.prototype._construct = _construct;
function writeAll(data, size, pos, cb, retries = 0) {

View File

@ -2,16 +2,5 @@
const common = require('../common');
const fs = require('fs');
common.expectWarning(
'DeprecationWarning',
'ReadStream.prototype.open() is deprecated', 'DEP0135');
const s = fs.createReadStream('asd')
// We don't care about errors in this test.
.on('error', () => {});
s.open();
process.nextTick(() => {
// Allow overriding open().
fs.ReadStream.prototype.open = common.mustCall();
fs.createReadStream('asd');
});
fs.ReadStream.prototype.open = common.mustCall();
fs.createReadStream('asd');

View File

@ -22,15 +22,6 @@ if (process.argv[2] !== 'child') {
}
// Child
common.expectWarning(
'DeprecationWarning',
'WriteStream.prototype.open() is deprecated', 'DEP0135');
const s = fs.createWriteStream(`${tmpdir.path}/out`);
s.open();
process.nextTick(() => {
// Allow overriding open().
fs.WriteStream.prototype.open = common.mustCall();
fs.createWriteStream('asd');
});
// Allow overriding open().
fs.WriteStream.prototype.open = common.mustCall();
fs.createWriteStream('asd');