Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
jasnell committed May 31, 2025
commit 9b2ae286adeba0cc8bf3ef8ecd1a9e418328f990
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2807,12 +2807,15 @@

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/00000

Check warning on line 2811 in doc/api/deprecations.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
Comment thread
jasnell marked this conversation as resolved.
Outdated
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
Expand Down
13 changes: 1 addition & 12 deletions lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const {
ERR_SYSTEM_ERROR,
} = require('internal/errors').codes;
const {
deprecate,
kEmptyObject,
} = require('internal/util');
const {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 2 additions & 13 deletions test/parallel/test-fs-read-stream-patch-open.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
15 changes: 3 additions & 12 deletions test/parallel/test-fs-write-stream-patch-open.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Loading