From a273674deed0a28d4eb4d4979e879139b14baa3e Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 2 Jun 2025 09:54:31 -0700 Subject: [PATCH] fs: move fs stream open method to eol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Yagiz Nizipli Reviewed-By: LiviaMedeiros Reviewed-By: Michaƫl Zasso Reviewed-By: Jason Zhang --- doc/api/deprecations.md | 5 ++++- lib/internal/fs/streams.js | 13 +------------ test/parallel/test-fs-read-stream-patch-open.js | 15 ++------------- test/parallel/test-fs-write-stream-patch-open.js | 15 +++------------ 4 files changed, 10 insertions(+), 38 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 493a92c102..ddb7da5007 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2810,12 +2810,15 @@ an officially supported API. -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 diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index 43f06d0104..79345a656e 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -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) { diff --git a/test/parallel/test-fs-read-stream-patch-open.js b/test/parallel/test-fs-read-stream-patch-open.js index 6fa97737b1..fbca4f578d 100644 --- a/test/parallel/test-fs-read-stream-patch-open.js +++ b/test/parallel/test-fs-read-stream-patch-open.js @@ -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'); diff --git a/test/parallel/test-fs-write-stream-patch-open.js b/test/parallel/test-fs-write-stream-patch-open.js index 9e7bb06af5..88c4db469d 100644 --- a/test/parallel/test-fs-write-stream-patch-open.js +++ b/test/parallel/test-fs-write-stream-patch-open.js @@ -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');