Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
stream: refactor code style
  • Loading branch information
marco-ippolito committed Jan 25, 2023
commit 958633dd2ad99e170a38fec0df09264c9f94328c
9 changes: 5 additions & 4 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ function WritableState(options, stream, isDuplex) {
// encoding is 'binary' so we have to make this configurable.
// Everything else in the universe uses 'utf8', though.
const defaultEncoding = options?.defaultEncoding;

if (defaultEncoding && !Buffer.isEncoding(defaultEncoding)) {
if (defaultEncoding == null) {
this.defaultEncoding = 'utf8';
} else if (Buffer.isEncoding(defaultEncoding)) {
this.defaultEncoding = defaultEncoding;
} else {
throw new ERR_UNKNOWN_ENCODING(defaultEncoding);
}
Comment thread
marco-ippolito marked this conversation as resolved.

this.defaultEncoding = defaultEncoding || 'utf8';

// Not an actual buffer we keep track of, but a measurement
// of how much we're waiting to get pushed to some underlying
// socket or file.
Expand Down