Skip to content

Commit a273674

Browse files
authored
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: #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>
1 parent df16f0f commit a273674

File tree

4 files changed

+10
-38
lines changed

4 files changed

+10
-38
lines changed

doc/api/deprecations.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2810,12 +2810,15 @@ an officially supported API.
28102810

28112811
<!-- YAML
28122812
changes:
2813+
- version: REPLACEME
2814+
pr-url: https://github.com/nodejs/node/pull/58529
2815+
description: End-of-Life.
28132816
- version: v13.0.0
28142817
pr-url: https://github.com/nodejs/node/pull/29061
28152818
description: Runtime deprecation.
28162819
-->
28172820

2818-
Type: Runtime
2821+
Type: End-of-Life
28192822

28202823
[`WriteStream.open()`][] and [`ReadStream.open()`][] are undocumented internal
28212824
APIs that do not make sense to use in userland. File streams should always be

lib/internal/fs/streams.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const {
1919
ERR_SYSTEM_ERROR,
2020
} = require('internal/errors').codes;
2121
const {
22-
deprecate,
2322
kEmptyObject,
2423
} = require('internal/util');
2524
const {
@@ -52,7 +51,7 @@ function _construct(callback) {
5251
return;
5352
}
5453

55-
if (stream.open !== openWriteFs && stream.open !== openReadFs) {
54+
if (typeof stream.open === 'function') {
5655
// Backwards compat for monkey patching open().
5756
const orgEmit = stream.emit;
5857
stream.emit = function(...args) {
@@ -238,11 +237,6 @@ ObjectDefineProperty(ReadStream.prototype, 'autoClose', {
238237
},
239238
});
240239

241-
const openReadFs = deprecate(function() {
242-
// Noop.
243-
}, 'ReadStream.prototype.open() is deprecated', 'DEP0135');
244-
ReadStream.prototype.open = openReadFs;
245-
246240
ReadStream.prototype._construct = _construct;
247241

248242
ReadStream.prototype._read = function(n) {
@@ -407,11 +401,6 @@ ObjectDefineProperty(WriteStream.prototype, 'autoClose', {
407401
},
408402
});
409403

410-
const openWriteFs = deprecate(function() {
411-
// Noop.
412-
}, 'WriteStream.prototype.open() is deprecated', 'DEP0135');
413-
WriteStream.prototype.open = openWriteFs;
414-
415404
WriteStream.prototype._construct = _construct;
416405

417406
function writeAll(data, size, pos, cb, retries = 0) {

test/parallel/test-fs-read-stream-patch-open.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,5 @@
22
const common = require('../common');
33
const fs = require('fs');
44

5-
common.expectWarning(
6-
'DeprecationWarning',
7-
'ReadStream.prototype.open() is deprecated', 'DEP0135');
8-
const s = fs.createReadStream('asd')
9-
// We don't care about errors in this test.
10-
.on('error', () => {});
11-
s.open();
12-
13-
process.nextTick(() => {
14-
// Allow overriding open().
15-
fs.ReadStream.prototype.open = common.mustCall();
16-
fs.createReadStream('asd');
17-
});
5+
fs.ReadStream.prototype.open = common.mustCall();
6+
fs.createReadStream('asd');

test/parallel/test-fs-write-stream-patch-open.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ if (process.argv[2] !== 'child') {
2222
}
2323

2424
// Child
25-
26-
common.expectWarning(
27-
'DeprecationWarning',
28-
'WriteStream.prototype.open() is deprecated', 'DEP0135');
29-
const s = fs.createWriteStream(`${tmpdir.path}/out`);
30-
s.open();
31-
32-
process.nextTick(() => {
33-
// Allow overriding open().
34-
fs.WriteStream.prototype.open = common.mustCall();
35-
fs.createWriteStream('asd');
36-
});
25+
// Allow overriding open().
26+
fs.WriteStream.prototype.open = common.mustCall();
27+
fs.createWriteStream('asd');

0 commit comments

Comments
 (0)