| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 039eb56 commit 773769d
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2532,6 +2532,22 @@ Type: Documentation-only (supports [`--pending-deprecation`][]) | |||
| 2532 | 2532 | The `process._tickCallback` property was never documented as | |
| 2533 | 2533 | an officially supported API. | |
| 2534 | 2534 | ||
| 2535 | + <a id="DEP0XXX"></a> | ||
| 2536 | + ### DEP0XXX: `WriteStream.open()` and `ReadStream.open()` are internal | ||
| 2537 | + <!-- YAML | ||
| 2538 | + changes: | ||
| 2539 | + - version: REPLACEME | ||
| 2540 | + pr-url: https://github.com/nodejs/node/pull/29061 | ||
| 2541 | + description: Runtime deprecation. | ||
| 2542 | + --> | ||
| 2543 | + | ||
| 2544 | + Type: Runtime | ||
| 2545 | + | ||
| 2546 | + [`WriteStream.open()`][] and [`ReadStream.open()`][] are undocumented internal | ||
| 2547 | + APIs that do not make sense to use in userland. File streams should always be | ||
| 2548 | + opened through their corresponding factory methods [`fs.createWriteStream()`][] | ||
| 2549 | + and [`fs.createReadStream()`][]) or by passing a file descriptor in options. | ||
| 2550 | + | ||
| 2535 | 2551 | [`--pending-deprecation`]: cli.html#cli_pending_deprecation | |
| 2536 | 2552 | [`--throw-deprecation`]: cli.html#cli_throw_deprecation | |
| 2537 | 2553 | [`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size | |
@@ -2542,10 +2558,12 @@ an officially supported API. | |||
| 2542 | 2558 | [`Decipher`]: crypto.html#crypto_class_decipher | |
| 2543 | 2559 | [`EventEmitter.listenerCount(emitter, eventName)`]: events.html#events_eventemitter_listenercount_emitter_eventname | |
| 2544 | 2560 | [`REPLServer.clearBufferedCommand()`]: repl.html#repl_replserver_clearbufferedcommand | |
| 2561 | + [`ReadStream.open()`]: fs.html#fs_class_fs_readstream | ||
| 2545 | 2562 | [`Server.connections`]: net.html#net_server_connections | |
| 2546 | 2563 | [`Server.getConnections()`]: net.html#net_server_getconnections_callback | |
| 2547 | 2564 | [`Server.listen({fd: <number>})`]: net.html#net_server_listen_handle_backlog_callback | |
| 2548 | 2565 | [`SlowBuffer`]: buffer.html#buffer_class_slowbuffer | |
| 2566 | + [`WriteStream.open()`]: fs.html#fs_class_fs_writestream | ||
| 2549 | 2567 | [`assert`]: assert.html | |
| 2550 | 2568 | [`asyncResource.runInAsyncScope()`]: async_hooks.html#async_hooks_asyncresource_runinasyncscope_fn_thisarg_args | |
| 2551 | 2569 | [`child_process`]: child_process.html | |
@@ -2568,6 +2586,8 @@ an officially supported API. | |||
| 2568 | 2586 | [`ecdh.setPublicKey()`]: crypto.html#crypto_ecdh_setpublickey_publickey_encoding | |
| 2569 | 2587 | [`emitter.listenerCount(eventName)`]: events.html#events_emitter_listenercount_eventname | |
| 2570 | 2588 | [`fs.access()`]: fs.html#fs_fs_access_path_mode_callback | |
| 2589 | + [`fs.createReadStream()`]: fs.html#fs_fs_createreadstream_path_options | ||
| 2590 | + [`fs.createWriteStream()`]: fs.html#fs_fs_createwritestream_path_options | ||
| 2571 | 2591 | [`fs.exists(path, callback)`]: fs.html#fs_fs_exists_path_callback | |
| 2572 | 2592 | [`fs.lchmod(path, mode, callback)`]: fs.html#fs_fs_lchmod_path_mode_callback | |
| 2573 | 2593 | [`fs.lchmodSync(path, mode)`]: fs.html#fs_fs_lchmodsync_path_mode | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ const { Math, Object } = primordials; | |||
| 5 | 5 | const { | |
| 6 | 6 | ERR_OUT_OF_RANGE | |
| 7 | 7 | } = require('internal/errors').codes; | |
| 8 | + const internalUtil = require('internal/util'); | ||
| 8 | 9 | const { validateNumber } = require('internal/validators'); | |
| 9 | 10 | const fs = require('fs'); | |
| 10 | 11 | const { Buffer } = require('buffer'); | |
@@ -100,7 +101,7 @@ function ReadStream(path, options) { | |||
| 100 | 101 | } | |
| 101 | 102 | ||
| 102 | 103 | if (typeof this.fd !== 'number') | |
| 103 | - this.open(); | ||
| 104 | + _openReadFs(this); | ||
| 104 | 105 | ||
| 105 | 106 | this.on('end', function() { | |
| 106 | 107 | if (this.autoClose) { | |
@@ -111,23 +112,34 @@ function ReadStream(path, options) { | |||
| 111 | 112 | Object.setPrototypeOf(ReadStream.prototype, Readable.prototype); | |
| 112 | 113 | Object.setPrototypeOf(ReadStream, Readable); | |
| 113 | 114 | ||
| 114 | - ReadStream.prototype.open = function() { | ||
| 115 | - fs.open(this.path, this.flags, this.mode, (er, fd) => { | ||
| 115 | + const openReadFs = internalUtil.deprecate(function() { | ||
| 116 | + _openReadFs(this); | ||
| 117 | + }, 'ReadStream.prototype.open() is deprecated', 'DEP0XXX'); | ||
| 118 | + ReadStream.prototype.open = openReadFs; | ||
| 119 | + | ||
| 120 | + function _openReadFs(stream) { | ||
| 121 | + // Backwards compat for overriden open. | ||
| 122 | + if (stream.open !== openReadFs) { | ||
| 123 | + stream.open(); | ||
| 124 | + return; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + fs.open(stream.path, stream.flags, stream.mode, (er, fd) => { | ||
| 116 | 128 | if (er) { | |
| 117 | - if (this.autoClose) { | ||
| 118 | - this.destroy(); | ||
| 129 | + if (stream.autoClose) { | ||
| 130 | + stream.destroy(); | ||
| 119 | 131 | } | |
| 120 | - this.emit('error', er); | ||
| 132 | + stream.emit('error', er); | ||
| 121 | 133 | return; | |
| 122 | 134 | } | |
| 123 | 135 | ||
| 124 | - this.fd = fd; | ||
| 125 | - this.emit('open', fd); | ||
| 126 | - this.emit('ready'); | ||
| 136 | + stream.fd = fd; | ||
| 137 | + stream.emit('open', fd); | ||
| 138 | + stream.emit('ready'); | ||
| 127 | 139 | // Start the flow of data. | |
| 128 | - this.read(); | ||
| 140 | + stream.read(); | ||
| 129 | 141 | }); | |
| 130 | - }; | ||
| 142 | + } | ||
| 131 | 143 | ||
| 132 | 144 | ReadStream.prototype._read = function(n) { | |
| 133 | 145 | if (typeof this.fd !== 'number') { | |
@@ -266,7 +278,7 @@ function WriteStream(path, options) { | |||
| 266 | 278 | this.setDefaultEncoding(options.encoding); | |
| 267 | 279 | ||
| 268 | 280 | if (typeof this.fd !== 'number') | |
| 269 | - this.open(); | ||
| 281 | + _openWriteFs(this); | ||
| 270 | 282 | } | |
| 271 | 283 | Object.setPrototypeOf(WriteStream.prototype, Writable.prototype); | |
| 272 | 284 | Object.setPrototypeOf(WriteStream, Writable); | |
@@ -279,21 +291,32 @@ WriteStream.prototype._final = function(callback) { | |||
| 279 | 291 | callback(); | |
| 280 | 292 | }; | |
| 281 | 293 | ||
| 282 | - WriteStream.prototype.open = function() { | ||
| 283 | - fs.open(this.path, this.flags, this.mode, (er, fd) => { | ||
| 294 | + const openWriteFs = internalUtil.deprecate(function() { | ||
| 295 | + _openWriteFs(this); | ||
| 296 | + }, 'WriteStream.prototype.open() is deprecated', 'DEP0XXX'); | ||
| 297 | + WriteStream.prototype.open = openWriteFs; | ||
| 298 | + | ||
| 299 | + function _openWriteFs(stream) { | ||
| 300 | + // Backwards compat for overriden open. | ||
| 301 | + if (stream.open !== openWriteFs) { | ||
| 302 | + stream.open(); | ||
| 303 | + return; | ||
| 304 | + } | ||
| 305 | + | ||
| 306 | + fs.open(stream.path, stream.flags, stream.mode, (er, fd) => { | ||
| 284 | 307 | if (er) { | |
| 285 | - if (this.autoClose) { | ||
| 286 | - this.destroy(); | ||
| 308 | + if (stream.autoClose) { | ||
| 309 | + stream.destroy(); | ||
| 287 | 310 | } | |
| 288 | - this.emit('error', er); | ||
| 311 | + stream.emit('error', er); | ||
| 289 | 312 | return; | |
| 290 | 313 | } | |
| 291 | 314 | ||
| 292 | - this.fd = fd; | ||
| 293 | - this.emit('open', fd); | ||
| 294 | - this.emit('ready'); | ||
| 315 | + stream.fd = fd; | ||
| 316 | + stream.emit('open', fd); | ||
| 317 | + stream.emit('ready'); | ||
| 295 | 318 | }); | |
| 296 | - }; | ||
| 319 | + } | ||
| 297 | 320 | ||
| 298 | 321 | ||
| 299 | 322 | WriteStream.prototype._write = function(data, encoding, cb) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const fs = require('fs'); | ||
| 4 | + | ||
| 5 | + common.expectWarning( | ||
| 6 | + 'DeprecationWarning', | ||
| 7 | + 'ReadStream.prototype.open() is deprecated', 'DEP0XXX'); | ||
| 8 | + const s = fs.createReadStream('asd') | ||
| 9 | + // We don't care about errors in this test. | ||
| 10 | + .on('error', () => {}); | ||
| 11 | + s.open(); | ||
| 12 | + | ||
| 13 | + // Allow overriding open(). | ||
| 14 | + fs.ReadStream.prototype.open = common.mustCall(); | ||
| 15 | + fs.createReadStream('asd'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,34 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const fs = require('fs'); | ||
| 4 | + | ||
| 5 | + const tmpdir = require('../common/tmpdir'); | ||
| 6 | + | ||
| 7 | + // Run in a child process because 'out' is opened twice, blocking the tmpdir | ||
| 8 | + // and preventing cleanup. | ||
| 9 | + if (process.argv[2] !== 'child') { | ||
| 10 | + // Parent | ||
| 11 | + const assert = require('assert'); | ||
| 12 | + const { fork } = require('child_process'); | ||
| 13 | + tmpdir.refresh(); | ||
| 14 | + | ||
| 15 | + // Run test | ||
| 16 | + const child = fork(__filename, ['child'], { stdio: 'inherit' }); | ||
| 17 | + child.on('exit', common.mustCall(function(code) { | ||
| 18 | + assert.strictEqual(code, 0); | ||
| 19 | + })); | ||
| 20 | + | ||
| 21 | + return; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + // Child | ||
| 25 | + | ||
| 26 | + common.expectWarning( | ||
| 27 | + 'DeprecationWarning', | ||
| 28 | + 'WriteStream.prototype.open() is deprecated', 'DEP0XXX'); | ||
| 29 | + const s = fs.createWriteStream(`${tmpdir.path}/out`); | ||
| 30 | + s.open(); | ||
| 31 | + | ||
| 32 | + // Allow overriding open(). | ||
| 33 | + fs.WriteStream.prototype.open = common.mustCall(); | ||
| 34 | + fs.createWriteStream('asd'); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments