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

doc: notes about forwarding stream options #29857

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -1645,13 +1645,24 @@ parent class constructor:
const { Writable } = require('stream');

class MyWritable extends Writable {
constructor(options) {
super(options);
constructor({ highWaterMark, ...options }) {
super({
highWaterMark,
lpinca marked this conversation as resolved.
Show resolved Hide resolved
autoDestroy: true,
emitClose: true
});
// ...
}
}
```

When extending streams it is important to keep in mind what options the user
ronag marked this conversation as resolved.
Show resolved Hide resolved
can and should provide before forwarding these to the base constructor. For
example if the implementation makes assumptions in regard to e.g. the
ronag marked this conversation as resolved.
Show resolved Hide resolved
`autoDestroy` and `emitClose` options, it becomes important to not allow the
user to override these. It is therefore recommend to be explicit about what
ronag marked this conversation as resolved.
Show resolved Hide resolved
options are forwarded instead of implicitly forwarding all options.

The new stream class must then implement one or more specific methods, depending
on the type of stream being created, as detailed in the chart below:

Expand Down