Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

correct example code#14002

Closed
AlexKVal wants to merge 1 commit intonodejs:masterfrom
AlexKVal:patch-1
Closed

correct example code#14002
AlexKVal wants to merge 1 commit intonodejs:masterfrom
AlexKVal:patch-1

Conversation

@AlexKVal
Copy link
Copy Markdown

No description provided.

@misterdjules
Copy link
Copy Markdown

Thanks @AlexKVal for your contribution! The sample code describes the normal usage of stream.Writable.end(), so I don't think we want it to trigger an error.

However I agree that it's slightly confusing since the example is right after the sentence Calling write() after calling end() will raise an error..

Maybe we could have the normal use case sample code before that sentence, and have a specific code sample for the write-after-end error after that sentence?

What do you think?

@AlexKVal
Copy link
Copy Markdown
Author

Agree. I had written it without thinking some steps ahead.

Something like this ?

The right way:
right example code

The wrong way:
wrong example code

@misterdjules
Copy link
Copy Markdown

@AlexKVal Right, something like:

Call this method when no more data will be written to the stream. If supplied, the callback is attached as a listener on the finish event.

// write 'hello, ' and then end with 'world!'
var file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');

Calling write() after calling end() will raise an error:

// end with 'world!' and then write with 'hello, ' will raise an error
var file = fs.createWriteStream('example.txt');
file.end('world!');
file.write('hello, ');

@AlexKVal
Copy link
Copy Markdown
Author

I'm closing this PR because of #15517.

@AlexKVal AlexKVal closed this Apr 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants