-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs: add autoClose option to fs.createWriteStream #3679
Conversation
@jasnell @misterdjules As discussed I created a new pull request for autoClose feature. node-v0.x-archive/pull/25275 This PR can be landed on v5/v4/v0.12/v0.10 it would be really nice if i see this PR land :-) |
cc @nodejs/streams |
var common = require('../common'); | ||
var assert = require('assert'); | ||
var path = require('path'); | ||
var fs = require('fs'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use const
for imports?
Basic premise looks alright to me. The checks in the test can be made a little tighter. |
4a6f713
to
991b6f5
Compare
@bnoordhuis Done! I updated the review comments given by you. |
991b6f5
to
4400ee7
Compare
Overall this is fine, but as a semver-minor it woud not be able to land in v0.10, v0.12 or v4.x. |
@@ -876,6 +877,12 @@ than replacing it may require a `flags` mode of `r+` rather than the | |||
default mode `w`. The `defaultEncoding` can be `'utf8'`, `'ascii'`, `binary`, | |||
or `'base64'`. | |||
|
|||
If `autoClose` is false, then the file descriptor won't be closed, even if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would like to see this reworded a bit to make it absolutely obvious that the default behavior is autoClose = true. Perhaps move the third sentence to the front?
LGTM with one nit on the docs |
In your PR message, you write |
4400ee7
to
273c758
Compare
@jasnell @ronkorving Done! Updated the doc and commit message. Thanks! |
The PR message still says "true" instead of "false", sorry :) Commit message is 👍 |
@ronkorving Done! |
process.nextTick(function() { | ||
assert.strictEqual(stream.closed, true); | ||
assert.strictEqual(!stream.fd, true); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent errors.
@saquibkhan ... when you get a chance, please take a look at @bnoordhuis' comments, then please rebase and update :-) |
273c758
to
c82c2a9
Compare
stream.on('finish', common.mustCall(function() { | ||
process.nextTick(common.mustCall(function() { | ||
assert.strictEqual(stream.closed, undefined); | ||
assert.strictEqual(!stream.fd, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using ! to test fd is not null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you're specifically testing for not null, perhaps assert(stream.fd !== null)
would be better
@bnoordhuis @jasnell I have updated the code as per review comments. |
@saquibkhan "This branch has conflicts that must be resolved" |
@@ -1886,6 +1886,7 @@ function WriteStream(path, options) { | |||
this.mode = options.mode === undefined ? 0o666 : options.mode; | |||
|
|||
this.start = options.start; | |||
this.autoClose = options.autoClose === undefined ? true : options.autoClose; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a !!
on the last options.autoClose
to guarantee we have a Boolean.
3b9ffce
to
3f24d5c
Compare
@cjihrig @ronkorving @jasnell @bnoordhuis Updated the code as per the review comments.. LGTM |
LGTM pending CI |
Add support to fs.createWriteStream and fs.createWriteStream for an autoClose option that behaves similarly to the autoClose option supported by fs.createReadStream and fs.ReadStream. When an instance of fs.createWriteStream created with autoClose === false finishes, it is not destroyed. Its underlying fd is not closed and it is the responsibility of the user to close it.
3f24d5c
to
98849bc
Compare
@ronkorving @jasnell @bnoordhuis @cjihrig Can we merge? |
unrelated failure in CI |
Add support to fs.createWriteStream and fs.createWriteStream for an autoClose option that behaves similarly to the autoClose option supported by fs.createReadStream and fs.ReadStream. When an instance of fs.createWriteStream created with autoClose === false finishes, it is not destroyed. Its underlying fd is not closed and it is the responsibility of the user to close it. PR-URL: #3679 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Landed in 6039a7c |
Add support to fs.createWriteStream and fs.createWriteStream for an autoClose option that behaves similarly to the autoClose option supported by fs.createReadStream and fs.ReadStream. When an instance of fs.createWriteStream created with autoClose === false finishes, it is not destroyed. Its underlying fd is not closed and it is the responsibility of the user to close it. PR-URL: #3679 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Notable changes: * events: make sure console functions exist (Dave) #4479 * fs: add autoClose option to fs.createWriteStream (Saquib) #3679 * http: improves expect header handling (Daniel Sellers) #4501 * node: allow preload modules with -i (Evan Lucas) #4696 * v8,src: expose statistics about heap spaces (`v8.getHeapSpaceStatistics()`) (Ben Ripkens) #4463 * Minor performance improvements: - lib: Use arrow functions instead of bind where possible (Minwoo Jung) #3622 - module: cache stat() results more aggressively (Ben Noordhuis) #4575 - querystring: improve parse() performance (Brian White) #4675 PR-URL: #4742
Notable changes: * events: make sure console functions exist (Dave) #4479 * fs: add autoClose option to fs.createWriteStream (Saquib) #3679 * http: improves expect header handling (Daniel Sellers) #4501 * node: allow preload modules with -i (Evan Lucas) #4696 * v8,src: expose statistics about heap spaces (`v8.getHeapSpaceStatistics()`) (Ben Ripkens) #4463 * Minor performance improvements: - lib: Use arrow functions instead of bind where possible (Minwoo Jung) #3622 - module: cache stat() results more aggressively (Ben Noordhuis) #4575 - querystring: improve parse() performance (Brian White) #4675 PR-URL: #4742
Add support to fs.createWriteStream and fs.createWriteStream for an autoClose option that behaves similarly to the autoClose option supported by fs.createReadStream and fs.ReadStream. When an instance of fs.createWriteStream created with autoClose === false finishes, it is not destroyed. Its underlying fd is not closed and it is the responsibility of the user to close it. PR-URL: nodejs#3679 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Notable changes: * events: make sure console functions exist (Dave) nodejs#4479 * fs: add autoClose option to fs.createWriteStream (Saquib) nodejs#3679 * http: improves expect header handling (Daniel Sellers) nodejs#4501 * node: allow preload modules with -i (Evan Lucas) nodejs#4696 * v8,src: expose statistics about heap spaces (`v8.getHeapSpaceStatistics()`) (Ben Ripkens) nodejs#4463 * Minor performance improvements: - lib: Use arrow functions instead of bind where possible (Minwoo Jung) nodejs#3622 - module: cache stat() results more aggressively (Ben Noordhuis) nodejs#4575 - querystring: improve parse() performance (Brian White) nodejs#4675 PR-URL: nodejs#4742
Add support to fs.createWriteStream and fs.WriteStream for an autoClose
option that behaves similarly to the autoClose option supported by
fs.createReadStream and fs.ReadStream.
When an instance of fs.WriteStream created with autoClose === false finishes,
it is not destroyed. Its underlying fd is not closed and it is the
responsibility of the user to close it.