Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

saquibkhan
Copy link
Contributor

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.

@saquibkhan
Copy link
Contributor Author

@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 :-)

@Fishrock123
Copy link
Contributor

cc @nodejs/streams

@Fishrock123 Fishrock123 added fs Issues and PRs related to the fs subsystem / file system. stream Issues and PRs related to the stream subsystem. semver-minor PRs that contain new features and should be released in the next minor version. labels Nov 5, 2015
var common = require('../common');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
Copy link
Member

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?

@bnoordhuis
Copy link
Member

Basic premise looks alright to me. The checks in the test can be made a little tighter.

@saquibkhan
Copy link
Contributor Author

@bnoordhuis Done! I updated the review comments given by you.

@jasnell
Copy link
Member

jasnell commented Nov 5, 2015

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
Copy link
Member

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?

@jasnell
Copy link
Member

jasnell commented Nov 5, 2015

LGTM with one nit on the docs

@ronkorving
Copy link
Contributor

In your PR message, you write When an instance of fs.WriteStream created with autoClose === true finishes,, but I think you mean to say === false?

@saquibkhan
Copy link
Contributor Author

@jasnell @ronkorving Done! Updated the doc and commit message. Thanks!

@ronkorving
Copy link
Contributor

The PR message still says "true" instead of "false", sorry :) Commit message is 👍

@saquibkhan
Copy link
Contributor Author

@ronkorving Done!

process.nextTick(function() {
assert.strictEqual(stream.closed, true);
assert.strictEqual(!stream.fd, true);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent errors.

@jasnell
Copy link
Member

jasnell commented Nov 13, 2015

@saquibkhan ... when you get a chance, please take a look at @bnoordhuis' comments, then please rebase and update :-)

stream.on('finish', common.mustCall(function() {
process.nextTick(common.mustCall(function() {
assert.strictEqual(stream.closed, undefined);
assert.strictEqual(!stream.fd, false);
Copy link
Contributor Author

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

Copy link
Member

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

@saquibkhan
Copy link
Contributor Author

@bnoordhuis @jasnell I have updated the code as per review comments.

@ronkorving
Copy link
Contributor

@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;
Copy link
Contributor

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.

@saquibkhan saquibkhan force-pushed the feature-autoclose branch 2 times, most recently from 3b9ffce to 3f24d5c Compare December 10, 2015 15:36
@saquibkhan
Copy link
Contributor Author

@cjihrig @ronkorving @jasnell @bnoordhuis Updated the code as per the review comments.. LGTM

@cjihrig
Copy link
Contributor

cjihrig commented Dec 10, 2015

LGTM pending CI

@saquibkhan saquibkhan changed the title fs: add autoClose option to fs.WriteStream fs: add autoClose option to fs.createWriteStream Dec 11, 2015
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.
@saquibkhan
Copy link
Contributor Author

@ronkorving @jasnell @bnoordhuis @cjihrig Can we merge?

@jasnell
Copy link
Member

jasnell commented Jan 11, 2016

@jasnell
Copy link
Member

jasnell commented Jan 11, 2016

unrelated failure in CI

jasnell pushed a commit that referenced this pull request Jan 11, 2016
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>
@jasnell
Copy link
Member

jasnell commented Jan 11, 2016

Landed in 6039a7c

@jasnell jasnell closed this Jan 11, 2016
evanlucas pushed a commit that referenced this pull request Jan 18, 2016
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>
evanlucas added a commit that referenced this pull request Jan 20, 2016
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
evanlucas added a commit that referenced this pull request Jan 21, 2016
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
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
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>
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. semver-minor PRs that contain new features and should be released in the next minor version. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants