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

Documentation/Add 'close' events to fs.ReadStream, fs.WriteStream, etc per Issue #6484 #6499

Closed
wants to merge 8 commits into from
8 changes: 8 additions & 0 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ Stop watching for changes on the given `fs.FSWatcher`.

Emitted when the ReadStream's file is opened.

### Event: 'close'

Emitted when a ReadStream's file has ended or closed. Comes from fs.close() method.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe something more specific like "Emitted when the ReadStream's underlying file descriptor has been closed" and similarly for WriteStream?


### readStream.path

The path to the file the stream is reading from as specified in the first
Expand Down Expand Up @@ -238,6 +242,10 @@ on Unix systems, it never was.

Emitted when the WriteStream's file is opened.

### Event: 'close'

Emitted when a WriteStream's file has ended or closed. Comes from fs.close() method.

### writeStream.bytesWritten

The number of bytes written so far. Does not include data that is still queued
Expand Down
6 changes: 6 additions & 0 deletions doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,12 @@ Examples of writable streams include:
* [TCP sockets][]
* [child process stdin][]
* [`process.stdout`][], [`process.stderr`][]

Event: 'close'
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be prefixed with ####.


Emitted when the stream and any of its underlying resources (a file descriptor, for example) have been closed. The event indicates that no more events will be emitted, and no further computation will occur.
Copy link
Member

Choose a reason for hiding this comment

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

How does this differs from 'end'?
Should a user expect 'close' or 'end' to proceed? Which one happens first?

I will also move this block after 'end', meaning that 'end' is the preferred way of waiting for the end of a stream.

Copy link
Contributor Author

@jennabelle jennabelle May 2, 2016

Choose a reason for hiding this comment

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

@mcollina

I hesitate to move the 'Event: 'close'' block to after the 'Event: 'end'' block because these events seem to be in alphabetical order for better user experience.

The difference between 'close' and 'end' events:

  1. 'close' event - Whatever it is tied to, for example a stream, it is done now. This event comes from the fs.close() method and is optional. Not all streams emit this event.
  2. 'end' event - Waits for the current data to finish buffering. means no more data will be emitted. This event is tied to the end() function on Streams.


Not all streams will emit the 'close' event.
Copy link
Contributor

Choose a reason for hiding this comment

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

'close' needs to be surrounded by backticks to match the formatting from the Readable section.


#### Event: 'drain'

Expand Down